Re: [gentoo-user] /usr/bin/[ and coreutils

2011-11-07 Thread Claudio Roberto França Pereira
What about [[? I've seen scripts using [[ instead of only one [. Whats the
point/difference?


Re: [gentoo-user] /usr/bin/[ and coreutils

2011-11-07 Thread Pandu Poluan
On Nov 8, 2011 9:02 AM, Claudio Roberto França Pereira spide...@gmail.com
wrote:

 What about [[? I've seen scripts using [[ instead of only one [. Whats
the point/difference?

AFAIK [[ was originally a bash-specific built-in command that provides more
functionality than /bin/[, but can still use /bin/['s convoluted syntax.

The two converged quickly, though. IIRC [ is now also a bash built-in,
which still maintains compatibility with /bin/[

An example:

[ $VAR ] will produce an error if VAR is empty or unset, but [[ $VAR ]]
won't.

(for the former, you have to put double quotes around, e.g., [ $VAR] )

Rgds,


Re: [gentoo-user] /usr/bin/[ and coreutils

2011-11-07 Thread Pandu Poluan
On Nov 8, 2011 1:01 PM, Pandu Poluan pa...@poluan.info wrote:


 On Nov 8, 2011 9:02 AM, Claudio Roberto França Pereira 
spide...@gmail.com wrote:
 
  What about [[? I've seen scripts using [[ instead of only one [. Whats
the point/difference?

 AFAIK [[ was originally a bash-specific built-in command that provides
more functionality than /bin/[, but can still use /bin/['s convoluted
syntax.

 The two converged quickly, though. IIRC [ is now also a bash built-in,
which still maintains compatibility with /bin/[

 An example:

 [ $VAR ] will produce an error if VAR is empty or unset, but [[ $VAR ]]
won't.

 (for the former, you have to put double quotes around, e.g., [ $VAR] )


Uh... of course there should be a space between the second double-quote and
the closing bracket.

Rgds,


Re: [gentoo-user] /usr/bin/[ and coreutils

2011-10-13 Thread Jesús J . Guerrero Botella
Yes, it's a different binary, and it's perfectly usual to find it in a
Linux system.

But note that, at least in bash, you rarely will be using /usr/bin/[
unless you reference it using the full path (either in a relative or
absolute way). This is because bash has a builtin that takes over that
binary file. You can check that (or any other command) by using the
type instruction (again, this is for bash).

# LC_ALL=C type [
[ is a shell builtin

The same goes for 'test'.

Those binaries are probably there just in case that some init or
system script written for a standard bourne shell (like the busybox
one) needs it. But don't take my word for it. I am not sure right now.

-- 
Jesús Guerrero Botella



Re: [gentoo-user] /usr/bin/[ and coreutils

2011-10-13 Thread Alan McKinnon
On Thu, 13 Oct 2011 15:38:08 +0200
Jesús J. Guerrero Botella jesus.guerrero.bote...@gmail.com wrote:

 Yes, it's a different binary, and it's perfectly usual to find it in a
 Linux system.
 
 But note that, at least in bash, you rarely will be using /usr/bin/[
 unless you reference it using the full path (either in a relative or
 absolute way). This is because bash has a builtin that takes over that
 binary file. You can check that (or any other command) by using the
 type instruction (again, this is for bash).
 
 # LC_ALL=C type [
 [ is a shell builtin
 
 The same goes for 'test'.
 
 Those binaries are probably there just in case that some init or
 system script written for a standard bourne shell (like the busybox
 one) needs it. But don't take my word for it. I am not sure right now. 

You might not be sure, but that doesn't stop you still being correct :-)

The binaries are usually POSIX-compliant, whereas the builtins may
include extra bashisms (which tend to break apps expecting just
the basic POSIX behaviour)

-- 
Alan McKinnnon
alan.mckin...@gmail.com



Re: [gentoo-user] /usr/bin/[ and coreutils

2011-10-13 Thread Michael Mol
On Thu, Oct 13, 2011 at 9:50 AM, Alan McKinnon alan.mckin...@gmail.com wrote:
 On Thu, 13 Oct 2011 15:38:08 +0200
 Jesús J. Guerrero Botella jesus.guerrero.bote...@gmail.com wrote:

 Yes, it's a different binary, and it's perfectly usual to find it in a
 Linux system.

 But note that, at least in bash, you rarely will be using /usr/bin/[
 unless you reference it using the full path (either in a relative or
 absolute way). This is because bash has a builtin that takes over that
 binary file. You can check that (or any other command) by using the
 type instruction (again, this is for bash).

 # LC_ALL=C type [
 [ is a shell builtin

 The same goes for 'test'.

 Those binaries are probably there just in case that some init or
 system script written for a standard bourne shell (like the busybox
 one) needs it. But don't take my word for it. I am not sure right now.

 You might not be sure, but that doesn't stop you still being correct :-)

 The binaries are usually POSIX-compliant, whereas the builtins may
 include extra bashisms (which tend to break apps expecting just
 the basic POSIX behaviour)

I haven't encountered POSIX-dependent apps breaking on bash, but I
have encountered the reverse. My most annoying experience was when I
tried building cinelerra on Debian a few years back. Cinelerra's
script started with #!/bin/sh, but depended on bashisms--and I was
running dash.

-- 
:wq



Re: [gentoo-user] /usr/bin/[ and coreutils

2011-10-13 Thread Alan McKinnon
On Thu, 13 Oct 2011 09:59:21 -0400
Michael Mol mike...@gmail.com wrote:

  The binaries are usually POSIX-compliant, whereas the builtins may
  include extra bashisms (which tend to break apps expecting just
  the basic POSIX behaviour)  
 
 I haven't encountered POSIX-dependent apps breaking on bash, but I
 have encountered the reverse. My most annoying experience was when I
 tried building cinelerra on Debian a few years back. Cinelerra's
 script started with #!/bin/sh, but depended on bashisms--and I was
 running dash.

So you've also run into clueless devs and maintainers who know
almost nothing about shells?

Your example is an extreme one :-), but it's common enough to find
bashisms in scripts with an sh shebang 

-- 
Alan McKinnnon
alan.mckin...@gmail.com



Re: [gentoo-user] /usr/bin/[ and coreutils

2011-10-12 Thread William Kenworthy
On Wed, 2011-10-12 at 07:45 +0200, meino.cra...@gmx.de wrote:
 William Kenworthy bi...@iinet.net.au [11-10-12 07:40]:
  I have been checking my system for some deep seated problems and in the
  process, ran across the fact that equery files sys-apps/coreutils-8.7
  shows a file included called /usr/bin/[ - thats right, left square
  bracket!
  
  Is that a bug or if real, what would you use it for?  It doesnt seem to
  be on the file system ...
  
  moriah ~ # /usr/bin/[
  /usr/bin/[: missing `]'
  moriah ~ #
  
  doesnt show much!
  
  BillK
  
  
 
 Hi Wiiliam,
 
 this is a convenient 'abbreviation' or 'alias' for cobnstructs such this one
 
 if [ foo ] 
 then
 bar
 fi
 
 in shell scripting.
 
 Most shells have implemented this as a builtin (and 'test' also)
 though.
 
 HTH!
 
 Best regards,
 mcc
 
 

GAH! - now I remember ... goes back to my basic unix skills (or lack
of :) - must be getting old ...

Thanks all.

BillK






Re: [gentoo-user] /usr/bin/[ and coreutils

2011-10-12 Thread Jonas de Buhr
Am Tue, 11 Oct 2011 22:42:00 -0700
schrieb Canek Peláez Valdés can...@gmail.com:

 On Tue, Oct 11, 2011 at 10:35 PM, William Kenworthy
 bi...@iinet.net.au wrote:
  I have been checking my system for some deep seated problems and in
  the process, ran across the fact that equery files
  sys-apps/coreutils-8.7 shows a file included called /usr/bin/[ -
  thats right, left square bracket!
 
  Is that a bug or if real, what would you use it for?  It doesnt
  seem to be on the file system ...
 
  moriah ~ # /usr/bin/[
  /usr/bin/[: missing `]'
  moriah ~ #
 
  doesnt show much!
 
 Relax. It's an alias for test

technically it's not an alias, but different binaries

% ls -l /usr/bin/\[
-rwxr-xr-x 1 root root 35096 Jan 20  2011 /usr/bin/[
% ls -l /usr/bin/test
-rwxr-xr-x 1 root root 31000 Jan 20  2011 /usr/bin/test

built from the same source file coreutils/src/test.c with a 
#define LBRACKET
that mainly changes the behavior of the argument parser in case it is
built as [.


, so instead of using
 
 if test blah; then
 ...
 fi
 
 in bash, you can use
 
 if [ blah ]; then
 ...
 fi
 
 Just do /usr/bin/[ --help to get an idea. It has been there since I
 started using Linux, if I remember correctly, many years ago.
 
 Regards.


[gentoo-user] /usr/bin/[ and coreutils

2011-10-11 Thread William Kenworthy
I have been checking my system for some deep seated problems and in the
process, ran across the fact that equery files sys-apps/coreutils-8.7
shows a file included called /usr/bin/[ - thats right, left square
bracket!

Is that a bug or if real, what would you use it for?  It doesnt seem to
be on the file system ...

moriah ~ # /usr/bin/[
/usr/bin/[: missing `]'
moriah ~ #

doesnt show much!

BillK




Re: [gentoo-user] /usr/bin/[ and coreutils

2011-10-11 Thread Canek Peláez Valdés
On Tue, Oct 11, 2011 at 10:35 PM, William Kenworthy bi...@iinet.net.au wrote:
 I have been checking my system for some deep seated problems and in the
 process, ran across the fact that equery files sys-apps/coreutils-8.7
 shows a file included called /usr/bin/[ - thats right, left square
 bracket!

 Is that a bug or if real, what would you use it for?  It doesnt seem to
 be on the file system ...

 moriah ~ # /usr/bin/[
 /usr/bin/[: missing `]'
 moriah ~ #

 doesnt show much!

Relax. It's an alias for test, so instead of using

if test blah; then
...
fi

in bash, you can use

if [ blah ]; then
...
fi

Just do /usr/bin/[ --help to get an idea. It has been there since I
started using Linux, if I remember correctly, many years ago.

Regards.
-- 
Canek Peláez Valdés
Posgrado en Ciencia e Ingeniería de la Computación
Universidad Nacional Autónoma de México



Re: [gentoo-user] /usr/bin/[ and coreutils

2011-10-11 Thread Manuel McLure
On Tue, Oct 11, 2011 at 10:35 PM, William Kenworthy bi...@iinet.net.au wrote:
 I have been checking my system for some deep seated problems and in the
 process, ran across the fact that equery files sys-apps/coreutils-8.7
 shows a file included called /usr/bin/[ - thats right, left square
 bracket!

 Is that a bug or if real, what would you use it for?  It doesnt seem to
 be on the file system ...

 moriah ~ # /usr/bin/[
 /usr/bin/[: missing `]'
 moriah ~ #

 doesnt show much!

'/usr/bin/[' is a synonym for the '/usr/bin/test' utility. It's used
in shell scripts like

if [ -f /etc/passwd ] ; then
  ...

So don't worry. It's supposed to be there.
-- 
Manuel A. McLure WW1FA man...@mclure.org http://www.mclure.org
...for in Ulthar, according to an ancient and significant law,
no man may kill a cat.                       -- H.P. Lovecraft



Re: [gentoo-user] /usr/bin/[ and coreutils

2011-10-11 Thread meino . cramer
William Kenworthy bi...@iinet.net.au [11-10-12 07:40]:
 I have been checking my system for some deep seated problems and in the
 process, ran across the fact that equery files sys-apps/coreutils-8.7
 shows a file included called /usr/bin/[ - thats right, left square
 bracket!
 
 Is that a bug or if real, what would you use it for?  It doesnt seem to
 be on the file system ...
 
 moriah ~ # /usr/bin/[
 /usr/bin/[: missing `]'
 moriah ~ #
 
 doesnt show much!
 
 BillK
 
 

Hi Wiiliam,

this is a convenient 'abbreviation' or 'alias' for cobnstructs such this one

if [ foo ] 
then
bar
fi

in shell scripting.

Most shells have implemented this as a builtin (and 'test' also)
though.

HTH!

Best regards,
mcc