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

Re: Problems with Parameter Expansion :=



On Feb 14,  9:28pm, Heinrich Go%tzger wrote:
> Subject: Problems with Parameter Expansion :=
> 
> if [ ${NAME1:=""} = "true" ]
> then
>         echo "true"
> fi

> $ . script.sh
> odin
> script.sh:6: parse error: condition expected: =
> 
> Why does it not expand NAME1 to "" ?

We've actually just been having a discussion about this on zsh-workers.

${NAME1:=""} sets NAME1 to the empty string and then substitutes the
resulting value of $NAME1, which is exactly what the zsh docs say it
will do.

Bourne shell and ksh, however, set NAME1 to the empty string and then
substitute the empty string, which is not the same thing.

The most straightforward thing that will work in all of sh/ksh/zsh is

	if [ "${NAME1:=''}" = "true" ]

so that the entire ${...} is quoted.



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