bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] WIP: quote_string_for_globbing: unquoted backslash


From: Grisha Levit
Subject: Re: [PATCH] WIP: quote_string_for_globbing: unquoted backslash
Date: Wed, 11 Oct 2023 12:14:03 -0700

On Sat, Oct 7, 2023 at 10:42 AM Chet Ramey <chet.ramey@case.edu> wrote:
>
> On 9/26/23 2:50 AM, Grisha Levit wrote:
> > I'm not confident in what the right behavior is here, and maybe there is
> > no obvious one, but I _think_ this is not desirable:
> >
> > If an unquoted backslash is followed by a quoted globbing character,
> > quote_string_for_globbing will store the unquoted backslash and then also
> > another one to quote the character -- resulting in the originally quoted
> > character becoming unquoted:
> >
> > $ bash -cx '[[ \\FOO == $1"*" ]]' _ '\'; echo $?
> > + [[ \FOO == \\* ]]
> > 0
>
> It's hard to say. There's only one way to quote a character for globbing:
> using a backslash. The expansion of $1 isn't quoted, so there's no reason
> to quote that backslash, but the `*' is, so you have to quote it somehow,
> and the only way to do that is with a backslash.
>
> This behavior is compatible with ksh93, at least, so you can conclude
> that both implementations see it the same way.

I originally thought bash was _not_ ksh93 compatible because:

$ mkdir '\X'
$ B=\\ bash  -c 'echo $B\*'
\X
$ B=\\ ksh93 -c 'echo $B\*'
\*

But I suspect that's a ksh93 bug, because its pattern matching in `case'
or `[[' commands works the same as in bash.

In any case, after some more testing I see that there's quite a lot of
variability between shells here so no need to change anything in bash.

       glob     case
       $B* $B\* $B* $B\*
bash   N   Y    N   Y
dash   N   Y    N   Y
yash   N   Y    N   Y
ksh93  N   N    N   Y
mksh   Y   N    Y   N
oksh   Y   N    Y   N
posh   Y   N    Y   N
zsh    Y   N    Y   N



reply via email to

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