|
Home > Archive > Unix administration > January 2006 > rookie question: test -n not the opposite of test -z?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
rookie question: test -n not the opposite of test -z?
|
|
| ffarzaneh@gmail.com 2006-01-20, 6:03 pm |
| 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:[vbcol=seagreen]
#!/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
| |
| S. Anthony Sequeira 2006-01-20, 8:49 pm |
| On Fri, 2006-01-20 at 15:20 -0800, ffarzaneh@gmail.com wrote:
> On my linux fedora core 4 system, the man pages for test indicate the
> following:
[...]
Try replacing the '()' with '[]'
--
S. Anthony Sequeira
++
QOTD:
"You want me to put *holes* in my ears and hang things from them?
How... tribal."
++
| |
| Jerry Peters 2006-01-22, 6: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
| |
| Moe Trin 2006-01-22, 6:11 pm |
| On 20 Jan 2006, in the Usenet newsgroup comp.unix.admin, in article
<1137799214.322257.13390@f14g2000cwb.googlegroups.com>, ffarzaneh@gmail.com
wrote:
>On my linux fedora core 4 system, the man pages for test indicate the
>following:
Doesn't it give examples?
>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
if ( test -z "$FOO" ) then
Try that - also remember to assign a value to FOO.
See
31540 Jul 27 2000 Bash-Prog-Intro-HOWTO
and
http://tldp.org/LDP/abs/html/index.html
Old guy
|
|
|
|
|