Re: Inconsistent handling of patterns with backslah (`\`) escaping

Andrei Borzenkov <[email protected]> Mon, 1 Jun 2026 11:08:49 +0300
Newsgroups gmane.comp.shells.bash.bugs
Message-ID <CAA91j0XAC=ebbPTJbgNPM0N=Op_-GHmbT3JeRUqbXh7Vu-4Lgw@mail.gmail.com>
On Sun, May 31, 2026 at 5:32 PM Andreas Schwab <[email protected]> wrote:
>
> On Mai 31 2026, Andrei Borzenkov wrote:
>
> > $ bar='\*'
> > $ ls $bar
> > ls: cannot access '\*': No such file or directory
> > $
> >
> > Oops. Why it suddenly attempts to match *two* characters "\*" instead of
> > just one literal "*"?
>
> Because '\*' is not a glob, so filename expansion is not performed.
>

If this is not a glob, I expect '\' to be stripped (quote removal)
before the result is used in the command.

bash is using unquoted_glob_pattern_p () to check "if STRING has any
unquoted special globbing chars in it". This function treats both
CTLESC and
'\' as quote characters. But subsequent dequote_string () only removes
CTLESC leaving '\' in place.