Re: if, -n string

2009-02-01 Thread coubeatczech


Jan Schampera wrote:
 
 coubeatczech wrote:
 
 c...@notas:~$ if [ -z $variable ]; then echo true; fi
 true
 c...@notas:~$
 
 Can anybody explain to me this behaviour? I would expect not any output
 in
 the last command...? The variable is set to zero and there is the
 condition
 is still true...?
 
 http://bash-hackers.org/wiki/doku.php/commands/classictest#number_of_arguments_rules
 
 You'd need some quoting.
 
 Jan aka TheBonsai
 
 
 
 
Thanks, I'm understanding it now.
-- 
View this message in context: 
http://www.nabble.com/if%2C--n-%3Cstring%3E-tp21764081p21774953.html
Sent from the Gnu - Bash mailing list archive at Nabble.com.





Re: if, -n string

2009-02-01 Thread Jan Schampera
coubeatczech wrote:

 c...@notas:~$ if [ -z $variable ]; then echo true; fi
 true
 c...@notas:~$
 
 Can anybody explain to me this behaviour? I would expect not any output in
 the last command...? The variable is set to zero and there is the condition
 is still true...?

http://bash-hackers.org/wiki/doku.php/commands/classictest#number_of_arguments_rules

You'd need some quoting.

Jan aka TheBonsai




Re: if, -n string

2009-01-31 Thread Eric Blake
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

According to coubeatczech on 1/31/2009 7:24 AM:
 c...@notas:~$ variable=
 c...@notas:~$ if [ -n $variable ]; then echo true; fi
 true

This is equivalent to 'if [ -n ]; then echo true; fi'; in other words,
because there is only one argument (-n), and it is not empty, it is true.

You meant to use quotes, to guarantee that there are two arguments, as in:

if [ -n $variable ]; then echo true; fi

- --
Don't work too hard, make some time for fun as well!

Eric Blake e...@byu.net
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.9 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkmFCUMACgkQ84KuGfSFAYCU6ACgj4hHK1Cxuk/gwI6QPo6xU0Ng
6KIAoMx3sk6bvV8YHGssez2s2vT7s45e
=VLoa
-END PGP SIGNATURE-