[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Interpretation of escapes in expansions in pattern matching contexts
From: |
Eric Blake |
Subject: |
Re: Interpretation of escapes in expansions in pattern matching contexts |
Date: |
Sat, 06 Apr 2013 07:01:38 -0600 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130311 Thunderbird/17.0.4 |
On 04/06/2013 02:48 AM, Dan Douglas wrote:
> I couldn't find anything obvious in POSIX that implies which interpretation is
> correct. Assuming it's unspecified.
Correct - POSIX does not specify [[ at all, so any behavior inside [[ is
unspecified.
>
> However, ksh93 (AJM 93v- 2013-03-17) is unique in that it flips the result
> depending on "[[ ]]" or "case..esac" (bug?), but otherwise it looks like a
> fairly random spread:
>
> x=\\x; case x in $x) echo yes;; *) echo no; esac
>
> bash: yes
The behavior inside case is specified by POSIX, and bash is correct in
returning 'yes'. POSIX requires that each case pattern undergoes
parameter expansion, and then the result of that expansion ('\x') is
compared against the expansion of word ('x') according to pattern
matching rules;
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_13.
Thos rules state that any character in the pattern that is quoted
(which \x is) matches itself, and 'x' matches 'x'.
> ksh: yes
correct
> mksh: no
bug
> posh: no
bug
> zsh: no
bug
> dash: yes
> bb: no
> jsh: no
I haven't heard of these two, but they are also bugs.
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature