rookie question: test -n not the opposite of test -z?
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix administration > rookie question: test -n not the opposite of test -z?




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    rookie question: test -n not the opposite of test -z?  
ffarzaneh@gmail.com


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-20-06 11: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






[ Post a follow-up to this message ]



    Re: rookie question: test -n not the opposite of test -z?  
S. Anthony Sequeira


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-21-06 01:49 AM

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







[ Post a follow-up to this message ]



    Re: rookie question: test -n not the opposite of test -z?  
Jerry Peters


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
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 ]



    Re: rookie question: test -n not the opposite of test -z?  
Moe Trin


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-22-06 11: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





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 07:48 PM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register