[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Bug in [ -d ... ] ?
From: |
Greg Wooledge |
Subject: |
Re: Bug in [ -d ... ] ? |
Date: |
Thu, 2 Nov 2017 09:47:24 -0400 |
User-agent: |
NeoMutt/20170113 (1.7.2) |
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 ]