Date:        Tue, 10 Apr 2018 13:41:25 +0100
    From:        Martijn Dekker <>
    Message-ID:  <>

  | Does POSIX specify anything, either way, regarding the effect of shell 
  | quoting within glob bracket patterns?

I would say it is unclear - in general, quoting inside [] does not work
(XCU 2.13 char classes are derived from XBD 9.3.5 char classes, and
in the latter, quote characters are just characters ["] is a char class 
containing just a double quote character.

Also, 2.13.1 does say:

        When pattern matching is used where shell quote removal is not 

[this includes case patterns as quote removal is not performed on them]

        special characters can be escaped to remove their special meaning by
        preceding them with a <backslash> character.

and that is the only quoting method provided.   That would suggest that


is first parameter expanded ($var becomes !a in one of the cases) resulting in


which is a character class that matches a double quote, an exclamation mark,
or an 'a' (including a character twice is harmless - though the terminating "
is needed here (somewhere) so the lexer can recognise the pattern word 

That said, in practice, shells implement, and people expect, that "" and ''
quoting works in case patterns, at least in expressions like

        case "$x" in '*') echo found an asterisk;; esac

even though this seems to be against the literal interpretation of 2.13.1 which
would require

        case "$x" in \*) echo found an asterisk;; esac

to achieve this effect - with the earlier one matching a string that starts and
ends with single quote chars, and has anything between them.

Regardless of the POSIX wording, I think this part is set in stone (that both of
the above match a literal asterisk) and should be clarified.

The effect of quotes inside [] though is much less clear.

Joerg: I suspect that the original Bourne sh behaviour is probably just an
artifact of the (crude) way that quoting was parsed in the lexer, which is
in no way posix (nor useful, nor implemented any more).   That would have
changed the '!' and '-' into things that were not those characters, 
unconditionally - hence they don't perform as they would if they appeared
unquoted.   That is, I do not believe that provides any useful help.

My interpretation from the standard of the correct expected result is
"quirk" for a-c (as ["a-c"] is a class containing a double quote, and all
chars from a to c (which includes b) but "no qurk" for !a as 'b' is none
of a double quote, an exclamation point, nor an 'a'.

The NetBSD sh however produces "no quirk" for both - again partly because
of the quirky way that it implements quoting in the lexer (different than the
original Bourns sh, but still not the same as POSIX expects.)


Reply via email to