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

Re: (#m) and "case" alternation

On Tue, 11 Nov 2014 17:43:26 +0000
Stephane Chazelas <stephane.chazelas@xxxxxxxxx> wrote:
> OK, but in:
> case abc in (#m)a* | b*) echo $MATCH; esac
> my understanding was that we've got two patterns as that's the
> "|" case alternation operator, not the "|" glob operator (with
> which you can't have spaces on either side)..

zsh is a bit different from other shells and the difference is a little
bit fudged --- so you and Bart are kind of both right.  We parse case
patterns separately, hence the whitespace handling, but after parsing we
weld the alternatives back together as one big group with an "or".  See
par_case() in parse.c, though that's probably not going to tell you much
further of interest.

It probably wouldn't hurt to document this.  Suggest improvements if the
following isn't clear enough...

diff --git a/Doc/Zsh/grammar.yo b/Doc/Zsh/grammar.yo
index 4d04c24..63d90df 100644
--- a/Doc/Zsh/grammar.yo
+++ b/Doc/Zsh/grammar.yo
@@ -239,7 +239,11 @@ item(tt(case) var(word) tt(in) [ [tt(LPAR())] var(pattern) [ tt(|) var(pattern)
 Execute the var(list) associated with the first var(pattern)
 that matches var(word), if any.  The form of the patterns
 is the same as that used for filename generation.  See
-noderef(Filename Generation).
+noderef(Filename Generation).  Note further that the whole
+pattern with alternatives is treated by the shell as equivalent
+to a group of patterns within parentheses, even though in
+the tt(case) syntax whitespace may appear about the parentheses and the
+vertical bar.
 If the var(list) that is executed is terminated with tt(;&) rather than
 tt(;;), the following list is also executed.  The rule for


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