[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Bug Report concerning backslash in bash5
From: |
Dale R. Worley |
Subject: |
Re: Bug Report concerning backslash in bash5 |
Date: |
Wed, 29 Jul 2020 01:35:32 -0400 |
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/
Dale