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

Re: 'case' pattern matching bug with bracket expressions



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.

What confounded me is that this applies even if the pattern is [$var] or
even ["$var"], where $var is empty. This causes the bracket pattern to
unexpectedly swallow anything that follows it if $var is empty. That
seems very unexpected and undesirable to me, particularly since, as far
as I know, zsh appears to be the only shell that chooses to handle it
this way.

An unfortunate ambiguity does appear to exist in the standard that
allows this to happen. But perhaps it would be advisable for zsh to
follow the practice most (all?) other shells have chosen to take, where
[] unambiguously is a simple non-match. Alternatively, unambiguously
consider [] an error. This would at least block a ["$var"] where $var is
empty from unexpectedly swallowing arbitrary grammar that follows it.

Meanwhile, I've just become aware of another cross-platform shell
programming snag to add to my list. Thanks for the reply.

- Martijn



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