From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24235 invoked by alias); 8 May 2014 15:34:49 -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: 18788 Received: (qmail 7072 invoked from network); 8 May 2014 15:34:41 -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,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 From: Bart Schaefer Message-id: <140508083418.ZM14713@torch.brasslantern.com> Date: Thu, 08 May 2014 08:34:18 -0700 In-reply-to: <20140508122045.3c68c3fa@pwslap01u.europe.root.pri> Comments: In reply to Peter Stephenson "Re: globbing in conditional expressions" (May 8, 12:20pm) References: <20140507124101.GA53652@isis.sigpipe.cz> <20140507154407.660eb500@pwslap01u.europe.root.pri> <20140508105522.GE2052@tarsus.local2> <20140508122045.3c68c3fa@pwslap01u.europe.root.pri> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: zsh-users@zsh.org Subject: Re: globbing in conditional expressions MIME-version: 1.0 Content-type: text/plain; charset=us-ascii 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.