[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Interpretation of escapes in expansions in pattern matching contexts
From: |
Chet Ramey |
Subject: |
Re: Interpretation of escapes in expansions in pattern matching contexts |
Date: |
Sat, 06 Apr 2013 21:37:44 -0400 |
User-agent: |
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:17.0) Gecko/20130307 Thunderbird/17.0.4 |
On 4/6/13 4:48 AM, Dan Douglas wrote:
> I couldn't find anything obvious in POSIX that implies which interpretation is
> correct. Assuming it's unspecified.
>
> Bash (4.2.45) uniquely does interpret such escapes for [[, which makes me
> think this test should say "no":
>
> x=\\x; if [[ x == $x ]]; then echo yes; else echo no; fi
>
> bash: yes
> ksh: no
> mksh: no
> zsh: no
>
> 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
These two cases should not be different. They undergo the same expansions,
except that the conditional command adds quote removal, which doesn't
matter in this case. In both cases, you ask the pattern matching code
whether or not the string `x' matches the pattern `\x'.
You invoke the same pattern matching code on the same patterns, why would
you not get the same answer?
Chet
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU chet@case.edu http://cnswww.cns.cwru.edu/~chet/