bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: if, -n <string>


From: Eric Blake
Subject: Re: if, -n <string>
Date: Sat, 31 Jan 2009 19:30:27 -0700
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.19) Gecko/20081209 Thunderbird/2.0.0.19 Mnenhy/0.7.5.666

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

According to coubeatczech on 1/31/2009 7:24 AM:
> address@hidden:~$ variable=
> address@hidden:~$ 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             address@hidden
-----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-----




reply via email to

[Prev in Thread] Current Thread [Next in Thread]