01-22-06 11:11 PM
ffarzaneh@gmail.com wrote:
> On my linux fedora core 4 system, the man pages for test indicate the
> following:
> ...
> [-n] STRING
> the length of STRING is nonzero
>
> -z STRING
> the length of STRING is
> ...
>
> Which to me indicates that testing with -n should give the opposite
> result of -z. When executing the following code:
> #!/bin/sh
>
> if ( test -z $FOO ) then
> echo test -z returns true
> else
> echo test -z returns false
> fi
>
> if ( test -n $FOO ) then
> echo test -n returns true
> else
> echo test -n returns false
> fi
>
> if ( test $FOO ) then
> echo test returns true
> else
> echo test returns false
> fi
>
> <<<<<<<<<<<<<<<<<<
> I get the following result:
>
> test -z returns true
> test -n returns true
> test returns false
>
> Am I misunderstanding the man pages?
>
> Thanks
>
Drop the parenthesis. IIRC the parenthesis create a subshell. Also [
is an alias for test, so you can do test -z ... or [ -z ... ]. Make
sure you have a space after [ and before ].
Jerry
[ Post a follow-up to this message ]
|