[wplug] shell script madness

James O'Kane jo2y at midnightlinux.com
Wed Jul 16 10:39:55 EDT 2003


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...
> 

The trick is to notice that [ is really a command. (A symlink to 
/usr/bin/test on my machine and a builtin in bash I think).
If looks at the return code for [ and if it is 0 meaning a sucessful 
execution, then it takes the then branch, if it is non-zero, meaning an 
error or false statement, it takes the else branch.
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:
if 1
that's false, so it takes the else branch.


-james





More information about the wplug mailing list