Robert Elz <[email protected]> wrote:
> Date: Tue, 10 Apr 2018 13:41:25 +0100
> From: Martijn Dekker <[email protected]>
> Message-ID: <[email protected]>
>
> | 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.
The problem is that the term "quote removal" is not related to a real verified
shell implementation but rather explained by means of abstract wording that
tries to avoid being too close to a real algorithm.
In special: your example ["] does not work as your text might mean.
echo ["]
results in a secondary prompt with all roughly POSIX-like shells I am aware of,
including the historic Bourne Shell.
...
> 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
Both commands are 100% equivalent:
The historical Bourne Shell did convert 'a' and \a into a 'a' with the top bit
set in the parser and kept '"'s in the argument strings.
In the late 1980's Bourne Shell and ksh88 have been modified to convert 'a' and
\a
into a \a and a string like 'abc' into \a\b\c in the parser and keep '"'s in
the
argument strings.
During macro expansion, the historic Bourne Shell did convert "abc" strings into
the string abc with the top bit set on all characters and modern Bourne Shells
and ksh88 started to convert "abc" during macro expansion into \a\b\c, so this
prevents glob expansion for the related characters.
The code fragment:
var='a-c'
case b in ["$var"]) ...
is thus equivalent to:
case b in [\a\-\c]) ...
and since the '-' is quoted, this does not match, as the pattern is equivalent
to: [a\-c] that just lists the tree characters 'a', '-' and 'c'.
Jörg
--
EMail:[email protected] (home) Jörg Schilling D-13353 Berlin
[email protected] (work) Blog: http://schily.blogspot.com/
URL: http://cdrecord.org/private/ http://sf.net/projects/schilytools/files/'