bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Problem with if [ -d in bash 4.3.30


From: Chet Ramey
Subject: Re: Problem with if [ -d in bash 4.3.30
Date: Tue, 09 Dec 2014 09:41:43 -0500
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:24.0) Gecko/20100101 Thunderbird/24.6.0

On 12/9/14, 8:24 AM, Olivier TROCHERIE wrote:

> I would like to report to you a problem I encounter with bash 4.3.30.
> 
> In the following example, VAR is undefined.
> 
>  
> 
> With bash 3.2, when I run the following commands:
> 
>  
> 
> if [ -d ${VAR:=""} ]
> 
> then
> 
>   echo yes
> 
> else
> 
>   echo no
> 
> fi
> 
>  
> 
> I get the no answer (“” is not a directory: correct behaviour).
> 
>  
> 
> If I run the same commands with bash 4.3.30, I get the yes answer, which
> seems to be a bad behavior.
> 
> Would it be possible to fix this issue?

The bash-4.3 behavior is correct.  The ${VAR:=""} expands to a null string
after quote removal and results in [ -d ], which is true.

This was the result of a bug fix that appeared in bash-4.2 responding to a
Posix interpretation (issue 221).  Previous versions of bash handled the
${VAR:=""} word expansion by assigning the value obtained by performing
quote removal on the "" but returned the "" (without quote removal) as the
result of the expansion.  The fix was to return the same value that was
assigned to the variable as the result of the expansion.

Chet
-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU    address@hidden    http://cnswww.cns.cwru.edu/~chet/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]