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

Re: globbing in conditional expressions

On 31 May 2014 21:38, Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx> wrote:
> On Fri, 30 May 2014 20:19:42 +0100
> Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx> wrote:
>> On Fri, 30 May 2014 19:57:34 +0100
>> Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx> wrote:
>> > One thing we could do is make [[ ... = ... ]] expand its right hand
>> > argument the same way as normal command arguments when told to do so, so
>> > there's no retokenization.
>> No reason not to do this for all string arguments, I suppose --- there's
>> nothing here that's specific to pattern matching.
> Here's a finalish patch with test and documentation, if anyone wants to
> comment.  Haven't thought of a good reason not to do this, myself.
> diff --git a/NEWS b/NEWS
> index e4d747e..87e67fd 100644
> --- a/NEWS
> +++ b/NEWS
> @@ -58,6 +58,13 @@ between the right hand side of the screen (this causes problems with
>  some terminals).  It is not special and is not set by default; the
>  effect in that case is as if it was 1, as in previous versions.
> +If the option EXTENDED_GLOB is in effect, it is possible to force
> +globbing within conditional code using the [[ ... ]] syntax by flagging
> +that a certain string is a glob using the (#q) glob qualifier syntax.
> +The resulting glob is treated as a single argument.  For example,
> +[[ -n *.c(#qN) ]] tests whether there are any .c files in the current
> +directory.

I was looking at the NEWS file since I figured I should maybe add :^
there, when I noticed this section added in this patch. I suddenly
remembered this example in the manpage which for some reason did not
come to mind while this patch was being discussed;

       q      A `q' and everything up to the closing parenthesis of the globbing
              flags are ignored by the pattern matching code.  This is
intended to
              support the use of glob qualifiers, see below.  The
result is that the
              pattern `(#b)(*).c(#q.)' can be used both for globbing
and for match‐
              ing against a string.  In the former case, the `(#q.)'
will be treated
              as a glob qualifier and the `(#b)' will not be useful,
while in the
              latter case the `(#b)' is useful for backreferences and
the `(#q.)'
              will be ignored.  Note that colon modifiers in the glob
qualifiers are
              also not applied in ordinary pattern matching.

% [[ alpha.c = (#b)(*).c(#q.) ]]
zsh: no matches found: (#b)(*).c(#q.)

This example no longer works.

Mikael Magnusson

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