bug-bash
[Top][All Lists]
Advanced

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

Re: Backslash mysteriously disappears in command expansion when unescapi


From: Greg Wooledge
Subject: Re: Backslash mysteriously disappears in command expansion when unescaping would reference an existing file
Date: Wed, 22 May 2019 08:43:00 -0400
User-agent: Mutt/1.10.1 (2018-07-13)

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 <address@hidden>
>     Message-ID:  <address@hidden>
> 
>   | 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

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