[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 8/7] syntax-check: fix violations and implement sc_useless_qu
Re: [PATCH 8/7] syntax-check: fix violations and implement sc_useless_quotes_in_case_branch.
Tue, 22 Nov 2011 08:37:10 -0700
Mozilla/5.0 (X11; Linux x86_64; rv:7.0.1) Gecko/20110930 Thunderbird/7.0.1
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
>> 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
> 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:
$ case b in $a) echo one;; *) echo two;; esac
$ case b in "$a") echo one;; *) echo two;; esac
"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
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
Eric Blake address@hidden +1-919-301-3266
Libvirt virtualization library http://libvirt.org
Description: OpenPGP digital signature
Re: [PATCH 6/7] syntax-check: fix violations and implement sc_prohibit_test_const_follows_var., Stefano Lattarini, 2011/11/21
Re: [PATCH 1/7] syntax-check: fix violations and implement sc_useless_quotes_in_case., Eric Blake, 2011/11/21
Re: [PATCH 1/7] syntax-check: fix violations and implement sc_useless_quotes_in_case., Gary V. Vaughan, 2011/11/25
- Re: [PATCH 6/7] syntax-check: fix violations and implement sc_prohibit_test_const_follows_var., (continued)