On 11/22/2011 01:21 AM, Gary V. Vaughan wrote: >>> Likewise in the pattern expression; you could further change this to: >>> >>> case $lt_sysroot:$1 in >>> ?*:$lt_sysroot*) >> >> Good call, although narrowing the search down to eliminate false positives >> is a lot trickier in this case! >> >> I'm adding the following changeset to this series. Thanks! > > Actually, no, I take it back. I won't apply that patch since it causes tests > to fail for at least dash, bash and ksh. > > My reading of the opengroup specification agrees with us both that no > resplitting > should be done in the branch expressions of a case, but there is definitely > something odd going on that I don't really understand: >
> > Confusing! It seems any backslash escaped character will do, same > results with '\S\S' and '\S' as with the dollars above. Yet, with > the backslashes removed, all the above print 4 'good's. > > If it weren't for the fact that ksh, bash and dash all independently > behave the same way, I'd have called it a bug... any idea? Oh, I think I understand the issue: $ a=\* $ case b in $a) echo one;; *) echo two;; esac one $ case b in "$a") echo one;; *) echo two;; esac two POSIX states: "each pattern that labels a compound-list shall be subjected to tilde expansion, parameter expansion, command substitution, and arithmetic expansion, and the result of these expansions shall be compared against the expansion of word, according to the rules described in Section 2.13 (on page 2332) (which also describes the effect of quoting parts of the pattern)." which in turn states: "If any character (ordinary, shell special, or pattern special) is quoted, that pattern shall match the character itself. The shell special characters always require quoting." So, variable expansion is performed _prior_ to passing the pattern to fnmatch(), but quoting can occur either by \ or by "". In the case where $a is unquoted, we are passing fnmatch the string "*", but where $a was quoted, the shell is correctly treating * as a literal and passing fnmatch the string "\\*". Bash, ksh, and dash are correct; mksh and Solaris 10 (among other shells) are buggy. And I stand corrected - variable expansion in case labels _must_ be quoted if you want to literally match all characters that occur in that variable expansion. -- Eric Blake ebl...@redhat.com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature