[Top][All Lists]

[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

From: Eric Blake
Subject: Re: [PATCH 8/7] syntax-check: fix violations and implement sc_useless_quotes_in_case_branch.
Date: Tue, 22 Nov 2011 08:37:10 -0700
User-agent: 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
>>> ?*:$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
$ case b in "$a") echo one;; *) echo two;; esac

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

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   address@hidden    +1-919-301-3266
Libvirt virtualization library

Attachment: signature.asc
Description: OpenPGP digital signature

reply via email to

[Prev in Thread] Current Thread [Next in Thread]