From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29029 invoked by alias); 4 Aug 2014 17:16:08 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 32950 Received: (qmail 11285 invoked from network); 4 Aug 2014 17:16:05 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; bh=xgygzJEf3elMCBwVjuD03PWz0eqrUWnbQ1hh50PoG4s=; b=p/gfpUmzQY/u5mLrtp8GAH9INXShe9ZpkghbRYUuJpz/gnN7Tv7Es/xFGBGGHV2bI6 rG3r0ciUnJMCbeHiQ9UafC9Xse8j1iXhILklT7hmlWtWbG86lgeK0LCep5nZxcHXEF+A JFSSpCfrRmb1fLlUg5KFXKHUf5YCOSpA+l/vulZwxWY/uczyqmGlpkXums5Z0Y5E4kZV PQeoKZpKtsloCJGX43L9yCf4bSwiolWxyxuSr82NRHf28HiCOpMLpNICjXg0MggIcwcy X7+CBH2SZ144xBt/sqMnNLJtLDAz0mspuaHMxsNOpFsB56FstmdQnaECoyfdUhy3tcUo 1YLQ== MIME-Version: 1.0 X-Received: by 10.50.50.229 with SMTP id f5mr38672279igo.42.1407172561587; Mon, 04 Aug 2014 10:16:01 -0700 (PDT) In-Reply-To: <20140531203800.154fc92d@pws-pc.ntlworld.com> References: <20140507154407.660eb500@pwslap01u.europe.root.pri> <20140508105522.GE2052@tarsus.local2> <20140508122045.3c68c3fa@pwslap01u.europe.root.pri> <140508083418.ZM14713@torch.brasslantern.com> <20140508201936.GB53652@isis.sigpipe.cz> <140513084117.ZM22925@torch.brasslantern.com> <20140514041908.GF2471@tarsus.local2> <140514001819.ZM23478@torch.brasslantern.com> <20140515092901.GC2174@tarsus.local2> <140515075003.ZM28035@torch.brasslantern.com> <20140526235216.GC1920@tarsus.local2> <140529205956.ZM17410@torch.brasslantern.com> <20140530094752.4a116629@pwslap01u.europe.root.pri> <140530085542.ZM18304@torch.brasslantern.com> <20140530195734.1d9c5310@pws-pc.ntlworld.com> <20140530201942.580abc43@pws-pc.ntlworld.com> <20140531203800.154fc92d@pws-pc.ntlworld.com> Date: Mon, 4 Aug 2014 19:16:01 +0200 Message-ID: Subject: Re: globbing in conditional expressions From: Mikael Magnusson To: "Zsh Hackers' List" Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 31 May 2014 21:38, Peter Stephenson wrote: > On Fri, 30 May 2014 20:19:42 +0100 > Peter Stephenson wrote: >> On Fri, 30 May 2014 19:57:34 +0100 >> Peter Stephenson wrote: >> > One thing we could do is make [[ ... =3D ... ]] 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 glo= bbing 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=E2=80=90 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. However, % [[ alpha.c =3D (#b)(*).c(#q.) ]] zsh: no matches found: (#b)(*).c(#q.) This example no longer works. --=20 Mikael Magnusson