[wplug] shell script madness

Eric C. Cooper ecc at cmu.edu
Wed Jul 16 11:51:41 EDT 2003


On Wed, Jul 16, 2003 at 10:39:55AM -0400, James O'Kane wrote:
> This one time, at band camp, Alexandros Papadopoulos said:
> > I thought that if the test statement returns non-zero, the statement
> > executes, therefore rendering comparisons with zero in tests
> > completely redundant...
> 
> So the output of the grep stuff is 0,
> if [ 0 ] 
> 0 is false, so [ returns a non-zero error code, I'll say 1 for now:

No.  The [ 0 ] (test) command is testing whether the string "0" has
non-zero length.

Try

if [ 0 ] then echo yes; else echo no ; fi

in bash.

You need to use [ ... != 0 ] if you want to treat the text output of
a command like `wc -l` as a number.

-- 
Eric C. Cooper          e c c @ c m u . e d u



More information about the wplug mailing list