Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: 'case' pattern matching bug with bracket expressions



On Thu, 14 May 2015 16:47:49 +0100
Martijn Dekker <martijn@xxxxxxxx> wrote:
> Peter Stephenson schreef op 14-05-15 om 15:42:
> > This is the pattern:
> >  '['                   introducing bracketed expression
> >    '] | *[!a-z'        characters inside
> >  ']'                   end of bracketed expression
> >  '*'                   wildcard.
> 
> Ah ha, that makes sense of the whole thing. Thank you.
> 
> > I'm not really sure we *can* resolve this unambiguously the way you
> > want.  Is there something that forbids us from interpreting the pattern
> > that way?
> 
> Apparently not, as far as I can tell.

It occurs to me that other shells will treat whitespace as ending a
pattern for syntactic reasons, even if logically it can't:

[[ ' ' = [ ] ]]

works in zsh, but is a parse error in bash.

Usually zsh's behaviour is the more useful, because if the expression is
meaningful at all there has to be a closing brace(*).  But it's not
impossible it does break some rule about whitespace as separators ---
and you've come up with the first example I've ever seen of where it's
significant even if the alternative isn't an error.  So it might
be more useful to change this in POSIX compatibility mode, in which what
zsh users expect has never been a significant factor.

pws

(*) Relegated to a footnote because this is more of a rant than
a useful comment:  furthermore, the whole []] thing is designed
so that you *don't* need to quote characters in the [...].  So
do you, or don't you?  Bleugh.



Messages sorted by: Reverse Date, Date, Thread, Author