Date:        Fri, 14 Jun 2019 07:32:27 +0000
    From:        Austin Group Bug Tracker <[email protected]>
    Message-ID:  <[email protected]>

I don't think this is worthy of a note, but:

  | So the two meanings of \ can never both be applied to the same pattern.

Not quite.   I agree with your basic premise, but it does not lead to
quite that conclusion.

Consider (using case patterns, as they're easier to demonstrate, but
the same applies to globs and substring extraction):

        V='\.'

        case "$word" in
        \\$V)   printf %s\\n  "match: ${word}";;
        *)      printf %s\\n  "no match: ${word}";;
        esac

In that pattern, the \\ becomes \ (and a literal quoted char) following
normal shell quoting rules (it could have also been entered as '\'),
whereas the \ in $V is an escape char for the '.' that follows.   The
effect is to match the word '\.' and nothing else (since all sh matches
are anchored both ends).

What you mean to say, I believe, is that exactly one interpretation is
possible for each \ in the pattern, it is never ambiguous which applies.

Any \ entered in the shell script literally is always either a quoting
character, and is never seen as anything but that (it is never a \ char)
or has been quoted itself, and so is a quoted literal backslash char in
all contexts including patterns.

A \ that appears as the result of an expansion depends upon whether the
expansion was quoted (must have been within double quotes, or an equivalent
context like a here doc, or uselesslly, arithmetic) in which case it is
like everything else that has been quoted, a literal char, or if the
expansion was unquoted, the \ is then a pattern quoting char (and there
needs to be 2 of them to get a literal \ in the pattern that way).

  | I think we should make this clear by rearranging 2.13.1 to describe
  | them one after the other, emphasising the different contexts:

Seems reasonable to me.   As I (vaguelly) recall, I was supposed to
be proposing new text for some of this, but have been side tracked
by unrelated (nothing related to here) issues...

Apologies for dropping the ball on this ... but I will get to it, one
day, if occasionally reminded!

kre

ps: test the case statement (after setting V=\\.) by embedding it
in a loop like:

for word in whatever you like \. \\. \\\. \\\\. \\.\\. and anything more
do
        case.... esac
done



Reply via email to