On Wed, May 22, 2019 at 05:25:43PM +0700, Robert Elz wrote:
>     Date:        Tue, 21 May 2019 22:11:20 +0000
>     From:        Charles-Henri Gros <charles-henri.g...@synopsys.com>
>     Message-ID:  
> <b51a83f93b459b479b6c4c3fbfe3f9310156f52...@us01wembx1.internal.synopsys.com>
> 
>   | The existence or not of the file should not have any effect.
> 
> But it does, and is intended to.   If the mattern matches a file
> (when patyhname expanded as a result of the unquoted command substitution)
> you get the file name produced.   If it does not match a file,
> the pattern is left untouched.   That is the way that things are
> supposed to work.

With glob metacharacters, sure.  But none of the characters in his
variable are glob metacharacters.

There is definitely something weird happening here.

wooledg:/tmp/x$ echo "$BASH_VERSION"
5.0.3(1)-release
wooledg:/tmp/x$ touch 'a$.class'
wooledg:/tmp/x$ i='a\$.class'; echo {$i} "{$i}"
{a\$.class} {a\$.class}
wooledg:/tmp/x$ i='a\$.class'; echo $i "{$i}"
a$.class {a\$.class}

Other versions of bash, plus ksh and dash, don't behave this way.

wooledg:/tmp/x$ bash-2.05b
wooledg:/tmp/x$ i='a\$.class'; echo $i "{$i}"
a\$.class {a\$.class}

wooledg:/tmp/x$ bash-4.4
wooledg:/tmp/x$ i='a\$.class'; echo $i "{$i}"
a\$.class {a\$.class}

wooledg:/tmp/x$ ksh
$ i='a\$.class'; echo $i "{$i}"
a\$.class {a\$.class}

wooledg:/tmp/x$ dash
$ i='a\$.class'; echo $i "{$i}"
a\$.class {a\$.class}

It seems to be unique to bash 5.  If it's a bug fix, then I'm not
understanding the rationale.  Backslashes shouldn't be consumed during
glob expansion.

This is also not limited to $ alone.  It happens with letters too.

wooledg:/tmp/x$ touch i
wooledg:/tmp/x$ i='\i' j='\j'
wooledg:/tmp/x$ echo $i $j
i \j

Standard disclaimers apply.  Stop using unquoted variables and these
bugs will stop affecting you.  Nevertheless, Chet may want to take a
peek.

Reply via email to