On 7/29/20 1:35 AM, Dale R. Worley wrote:
> Ralph Beckmann <r...@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

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to