From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11991 invoked by alias); 8 May 2014 20:19:55 -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: 18789 Received: (qmail 13416 invoked from network); 8 May 2014 20:19:40 -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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham version=3.3.2 Date: Thu, 8 May 2014 22:19:36 +0200 From: Roman Neuhauser To: Bart Schaefer Cc: zsh-users@zsh.org Subject: Re: globbing in conditional expressions Message-ID: <20140508201936.GB53652@isis.sigpipe.cz> References: <20140507124101.GA53652@isis.sigpipe.cz> <20140507154407.660eb500@pwslap01u.europe.root.pri> <20140508105522.GE2052@tarsus.local2> <20140508122045.3c68c3fa@pwslap01u.europe.root.pri> <140508083418.ZM14713@torch.brasslantern.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <140508083418.ZM14713@torch.brasslantern.com> User-Agent: Mutt/1.5.21 (2010-09-15) # schaefer@brasslantern.com / 2014-05-08 08:34:18 -0700: > On May 8, 12:20pm, Peter Stephenson wrote: > } > } > All three solutions first set an array to the result of the glob. Is > } > there a solution that short-circuits, i.e., that returns as soon as a > } > single matching filename is found? > } > } No, unless someone remembers I feature I don't know about, because > } internally the glob proceeds until it's finished > > Well ... you can do this horrible hack: > > found= > # Stop after finding exactly one directory, for example: > : **/*(e+'[[ -d $REPLY ]] && { found=$REPLY ; kill -INT $$ }'+) > print $found > > Of course to make this "useful" all the stuff that you'd test in the > glob qualifiers you instead need to test in the [[ ... ]] before you > assign found=$REPLY, probably by using the zsh/stat module; and you > can't avoid scanning an unknown number of potential NON-matches up > to the point where $found gets set, so in the worst case it's no > better (and probably much worse) than just letting the glob finish. maybe a crazy idea... how about something like [[ -m pattern ]] which would succeed iff pattern matched at least one path? this could be somewhat more amenable to shortcircuiting. -- roman