Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #16643

Re: Bug Report concerning backslash in bash5

From worley@alum.mit.edu (Dale R. Worley)
Newsgroups gnu.bash.bug
Subject Re: Bug Report concerning backslash in bash5
Date 2020-07-29 01:35 -0400
Message-ID <mailman.227.1595986568.2739.bug-bash@gnu.org> (permalink)
References <15dff7a7b42bf7192b57066215723128@rbx.de> <87ft9azxwb.fsf@hobgoblin.ariadne.com>

Show all headers | View raw


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

Back to gnu.bash.bug | Previous | Next | Find similar


Thread

Re: Bug Report concerning backslash in bash5 worley@alum.mit.edu (Dale R. Worley) - 2020-07-29 01:35 -0400

csiph-web