From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3693 invoked by alias); 31 May 2014 17:34:32 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 18867 Received: (qmail 4094 invoked from network); 31 May 2014 17:34:17 -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,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= daniel.shahaf.name; h=date:from:to:cc:subject:message-id :references:mime-version:content-type:in-reply-to; s=mesmtp; bh= ZhHBVcZ3pyxPjY962A2Rp+7qo0Q=; b=eq0g579TKZYw2qSS12e49jIXxW1tzzUS Ltyc/D8Trb+j/YfrX0se7GTp4nkbgcoSmyq1p0m9OeSYqtXSuNpgAqd+TkoHJlbQ qM8Wt6d/fp0RHCVHfdhCGDDyELzsmFsqcuxY+xEfV0H6ko5mfNu6TznIIHmTY24f Of9hg/b8qqs= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=date:from:to:cc:subject:message-id :references:mime-version:content-type:in-reply-to; s=smtpout; bh=ZhHBVcZ3pyxPjY962A2Rp+7qo0Q=; b=W1Gc5LGNEaxhDMzuvVV8brjqEZtG J4K4HMvpO0qCuhwGGlEMAFlpn43uD8Sx1qCVmR+2hYy3pSVaGpeaj/a6popoHTp8 GtP4Rho2HA7xHwo2NG3/BzQ6gAXQCrIGLWhju1JnndAkH3NTvH1FsdjtIvmr6/d+ ig/CcfGctOb55Mk= X-Sasl-enc: 9NLuMXel0MIElsPdWL4XnUA8dGBd615vsuem6l2z5vZ2 1401557651 Date: Sat, 31 May 2014 17:34:06 +0000 From: Daniel Shahaf To: Bart Schaefer Cc: zsh-users@zsh.org Subject: Re: globbing in conditional expressions Message-ID: <20140531173406.GF2498@tarsus.local2> References: <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> <140530214320.ZM30732@torch.brasslantern.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <140530214320.ZM30732@torch.brasslantern.com> User-Agent: Mutt/1.5.21 (2010-09-15) Bart Schaefer wrote on Fri, May 30, 2014 at 21:43:20 -0700: > On May 30, 8:55am, Bart Schaefer wrote: > } > } Is there a non-convoluted way to have the special case of a glob with > } BOTH of the (NY) qualifiers return empty string rather than nularg when > } it finds no match? Empty string is an illegal file name so for most > } purposes it wouldn't otherwise affect usage. I beg to differ. Making *(NY) return empty strings upon no match is (by design) convenient for the [ -n *(NY) ] case, but it breaks other use-cases. For example, frob *.foo(NY) *.bar(NY) would suddenly need to handle "" files in the argument list. For testing whether the pattern expands to anything, this is already possible: if (){(($#@))} *(NY) and after naming the anon func, it becomes: if has_any_matches *(NY) which seems to me as readable as [ -n *(NY) ]. (For that matter, we could define a unary test operator [ --is-not-null ] that acts like -n except that it returns False rather than True in the nularg case, and write [ --is-not-null *(NY) ].) Perhaps an assignment-ish syntax would be useful? Something like if [ -n ${(X)fname:=*(NY)} ] as shorthand for: if _tmp=(*(NY)) && (( $#_tmp )) && fname=$_tmp[1] && [ -n $fname ] ? That way also makes the matching filename available for the if's body. (The X stands for an expansion modifier that would make the RHS be treated as a glob rather than as a literal string.) Cheers, Daniel > This turns out to be pretty simple. It'd additionally be nice if the > CSH_NULL_GLOB option caused any such empty strings to be removed when > some other pattern succeeds, but that seems rather far-reaching. (The > following will require a tweak to Daniel's test in D02glob.) > > diff --git a/Src/glob.c b/Src/glob.c > index 07dd7c2..5aa306b 100644 > --- a/Src/glob.c > +++ b/Src/glob.c > @@ -1748,6 +1761,11 @@ zglob(LinkList list, LinkNode np, int nountok) > matchptr++; > matchct = 1; > } > + } else if (shortcircuit) { > + /* treat as an empty string */ > + matchptr->name = dupstring(""); > + matchptr++; > + matchct = 1; > } > > if (!(gf_sortlist[0].tp & GS_NONE)) {