Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: beta 19 cannot run this script



Hello,

On Wed, 05 Jun 1996 14:31:00 EST, Carlos Carvalho wrote:
> I tried this and it doesn't work :-(

You didn't do exactly what Bart suggested!

You must put double quotes around "$APS_BASEDIR" to force [ -z ... ] to
see a null argument.  Without double quotes, [ -z ... ] might not see an
argument if the variable is empty or undefined!

The difference is that when $APS_BASEDIR is empty or undefined, the test
[ -z $APS_BASEDIR ] becomes [ -z ], which makes no sense, but written as
[ -z "$APS_BASEDIR" ], it becomes [ -z "" ], which makes perfect sense.

If you don't want to fuss with quotes, then you can write your script in
ksh syntax using [[ ... ]] instead of [ ... ].  This test syntax is fully
supported in zsh, but you will lose compatibility with /bin/sh.  Simply
say [[ -z $APS_BASEDIR ]] -- the advantage of [[ ... ]] is that undefined
and empty variables will be treated as null arguments.

Later,

Eskandar




Messages sorted by: Reverse Date, Date, Thread, Author