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

(#cN,M) error, %? doesn't glob



Someone asked on irc if there was a way to limit **/foo to 2 levels,
and I explained how **/ is short for (*/)# so he should be able to use
(*/)(#c,2), but that produces a bad pattern error. The manual says
that "The flag (#cN,M) can be used anywhere that the # or ## operators
can be used".

(*/)# is special-cased together with **/ in parsecomplist(), so it is
nontrivial to make it parse (#c) stuff, so here's an update for the
documentation to add an exception. Looking further, not just the
parsing but the whole scanner knows about this construct and hardcodes
0/1 or more dirs behaviour, so it would be a lot of work to change.

--- a/Doc/Zsh/expn.yo
+++ b/Doc/Zsh/expn.yo
@@ -1992,7 +1992,8 @@ point on.
 )
 item(tt(c)var(N)tt(,)var(M))(
 The flag tt(LPAR()#c)var(N)tt(,)var(M)tt(RPAR()) can be used anywhere
-that the tt(#) or tt(##) operators can be used; it cannot be combined
+that the tt(#) or tt(##) operators can be used except in the expressions
+`tt((*/)#)' and `tt((*/)##)'; it cannot be combined
 with other globbing flags and a bad pattern error occurs if it is
 misplaced.  It is equivalent to the form tt({)var(N)tt(,)var(M)tt(}) in
 regular expressions.  The previous character or group is required to


While looking at Src/glob.c I also noticed that ? is ignored for
globbing if it is preceded by a % at the start of a string, is that
documented anywhere? bash doesn't have this behaviour, and emulate sh
obviously doesn't help.
    /* If % is immediately followed by ?, then that ? is     *
     * not treated as a wildcard.  This is so you don't have *
     * to escape job references such as %?foo.               */
    if (str[0] == '%' && str[1] == Quest)
	str[1] = '?';
I would argue that if someone is too lazy to escape their job
references they should just setopt nonomatch. I can imagine files like
that existing if you downloaded some nonlatin filenames via http and
they were saved percent-escaped, then you might want to find such
files with %??%* or something, maybe? I know that at least I would be
very confused if zsh then told me "no matches found", viz,
% touch %ab%de
% echo %??%*
zsh: no matches found: %??%*
% echo (#)%??%*
%ab%de

I sort of feel like an explicit option for this would be a bit awkward.

-- 
Mikael Magnusson



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