On Thu, Nov 02, 2017 at 09:47:24AM -0400, Greg Wooledge wrote:
> Quoting failure.
>
> wooledg:~$ unset FOO
> wooledg:~$ if [ -d "${FOO:=""}" ]; then echo yes; else echo no; fi
> no
>
> With quotes the command is transformed to
>
> [ -d "" ]
>
> Without quotes it becomes
>
> [ -d ]
>
> A single-argument test command simply checks whether the string (-d in
> this case) is nonzero length. It is equivalent to
>
> [ -n -d ]
Interesting. This is the way "[" has always been documented to work, but
something has changed in newer versions of the shell - the unquoted version
if [ -d ${FOO:=""} ]; then echo yes; else echo no; fi
gives "yes" on 4.2 onwards but "no" on 4.1. Also, replacing := with :-
gives "no" on both versions when unquoted or unquoted. I think I'll just
rewrite this bit of the script to separate the assignment and test.
Michael
--
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.