On Thu, Nov 02, 2017 at 11:03:27AM +0000, Michael F Gordon wrote:
> Can anyone explain the following?
>
> tla19> set|grep FOOFOOFOO
> tla19> if [ -d ${FOOFOOFOO:=""} ]; then echo YES;fi
> YES
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 ]