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

Re: confusing passage in zshexpn(1)



Frank Terbeck wrote:
> Hi list,
> 
> Someone on IRC wondered about a problem with the following passage in
> zshexpn(1):
> 
> [snip]
>  x##    (Requires EXTENDED_GLOB to be set.) Matches one or more occur-
>         rences of the pattern x. This operator has high precedence;
>         '12##' is equivalent to '1(2##)', rather than '(12)##'. No
>         more than two active '#' characters may appear together.
> [snap]
> 
> Because of this part of the manual he tried this:
> % setopt EXTENDED_GLOB; touch 12222; echo 1(2##)
> zsh: unknown file attribute
> 
> That's because of the trailing parentheses in the globbing pattern.
> But the manual suggests that this should work.

Well, as Bart pointed out, no it doesn't, it's indicating precedence of
interpretation and nowhere says it's in the form you need to match a
file under every possible circumstance.  But it's easy to add a
cautionary note.

> How could the fact be included, that this pattern is okay to use in
> the following position?
> 
> [snip]
> % file=12222
> % [[ ${file} == 1(2##) ]] && print match.
> match.

Do you mean you're suggesting this as an alternative example that would
actually work?  I think I'll just stick with the warning note---it's
cleaner to write this as 12## anyway, without the parentheses.  That's
why you don't fall over the glob qualifier problem in practice:  you
only need the parentheses when there are #'s after them.

By the way, if you feel yourself susceptible to problems like this,
you can set both NO_BARE_GLOB_QUAL and EXTENDED_GLOB and use (#q...) for
glob qualifiers.

Index: Doc/Zsh/expn.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/expn.yo,v
retrieving revision 1.74
diff -u -r1.74 expn.yo
--- Doc/Zsh/expn.yo	7 Nov 2006 22:47:07 -0000	1.74
+++ Doc/Zsh/expn.yo	12 Dec 2006 10:34:23 -0000
@@ -1504,7 +1504,8 @@
 Matches one or more occurrences of the pattern var(x).
 This operator has high precedence; `tt(12##)' is equivalent to `tt(1(2##))',
 rather than `tt((12)##)'.  No more than two active `tt(#)' characters may
-appear together.
+appear together.  (Note the potential clash with glob qualifiers in the
+form `tt(1(2##))' which should therefore be avoided.)
 )
 enditem()
 subsect(ksh-like Glob Operators)

-- 
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070


To access the latest news from CSR copy this link into a web browser:  http://www.csr.com/email_sig.php



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