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: Robert Elz
Subject: Re: Backslash mysteriously disappears in command expansion when unescaping would reference an existing file
Date: Wed, 22 May 2019 20:33:47 +0700

    Date:        Wed, 22 May 2019 08:43:00 -0400
    From:        Greg Wooledge <wooledg@eeg.ccf.org>
    Message-ID:  <20190522124300.GZ1434@eeg.ccf.org>

  | 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.

They should - when a pattern comes from an expansion (be that a
variable expansion, or as here, a command substitution) there needs
to be a way to indicate whether the potential magic chars are in
fact intended as magic chars, or as literals.   \ is used for that.

If quoted, everything is literal, and there's no issue, but when
unquoted there needs to be this mechanism.   So, I think it was a
bug fix (I recently made very similar fixes to the NetBSD shell).

Uses of this kind of thing are obscure, but they exist.

Here, the $ isn't magic to pathname expansion (glob is not a RE)
so the \ doesn't do anything useful, but consider

        ls $( printf %s '\**.c' )

what that should do is list all files that end in .c and start
with an asterisk (star).   There the first '*' is to be treated
literally, and the 2nd is the "match anything" metc char.   Only
the presence of the \ can distinguish those two cases.   (Well, here
one could make the pattern be [*]*.c but that isn't always easy, or
even possible).

kre




reply via email to

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