[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Bug Report concerning backslash in bash5
From: |
Eli Schwartz |
Subject: |
Re: Bug Report concerning backslash in bash5 |
Date: |
Tue, 28 Jul 2020 22:41:52 -0400 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 |
On 7/29/20 1:35 AM, Dale R. Worley wrote:
> Ralph Beckmann <rb@rbx.de> writes:
>> I found this misbehaviour in Bash 5 (e.g. GNU bash, version
>> 5.0.16(1)-release (x86_64-pc-linux-gnu)):
>>
>> $ BLA="1\.2"; echo 'x/'$BLA'/y/'
>> \x/1\.2/\y/
>>
>> I don't see any reasonable reason for the generated backslashes here.
>
> My guess is that you're running into the fact that there are two types
> of quoting character. One quotes *any* character that follows it, and
> thus it never appears in "the output" unless it was doubled in the
> input. The other type *only* quotes characters that are somewhow
> special in that particular context. Reading the manual page:
>
> Enclosing characters in double quotes preserves the literal value of
> all characters within the quotes, with the exception of $, `, \, and,
> when history expansion is enabled, !. The characters $ and ` retain
> their special meaning within double quotes. The backslash retains its
> special meaning only when followed by one of the following characters:
> $, `, ", \, or <newline>.
>
> So backslash-inside-double-quotes-in-bash is of the second type, it only
> quotes things that would otherwise be special. So the value of $BLA is
> 1-\-.-2, whereas if the period was replaced by $, $BLA would only have 3
> characters:
>
> $ BLA="1\$2"; echo 'x/'$BLA'/y/'
> x/1$2/y/
>
I'm not sure what point you're trying to make here. Are you arguing that
*printing* these backslash escapes is valid behavior here, and the
reporter has merely misunderstood the shell rules?
--
Eli Schwartz
Arch Linux Bug Wrangler and Trusted User
signature.asc
Description: OpenPGP digital signature