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 c...@case.edu http://cnswww.cns.cwru.edu/~chet/