Re: Inconsistent handling of patterns with backslah (`\`) escaping
Andrei Borzenkov <[email protected]> Tue, 2 Jun 2026 16:04:16 +0300
| Newsgroups | gmane.comp.shells.bash.bugs |
|---|---|
| Message-ID | <CAA91j0W4OB=nNz3E0aPcrO6kx6zXBJRNiov4RR=0Mv1muJjKiw@mail.gmail.com> |
On Mon, Jun 1, 2026 at 6:07 PM Chet Ramey <[email protected]> wrote: > > On 5/31/26 10:32 AM, Andreas Schwab 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. > > The rationale in the POSIX standard (yes, I realize it's not normative) says: > > "Patterns are matched against existing filenames and pathnames only when > the pattern contains a '*', '?' or '[' character that will be treated as > special. This prevents accidental removal of <backslash> characters in > variable expansions where generating a list of matching files is not > intended and a (usually oddly named) file with a matching name happens to > exist." > > https://pubs.opengroup.org/onlinepubs/9799919799/xrat/V4_xcu_chap01.html#tag_23_02_14_04 > I see. Thank you! Sorry for the noise.