From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28453 invoked by alias); 8 May 2014 11:31:07 -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: 18787 Received: (qmail 28168 invoked from network); 8 May 2014 11:30:52 -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=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI, SPF_HELO_PASS autolearn=ham version=3.3.2 X-AuditID: cbfec7f5-b7fae6d000004d6d-8d-536b688e386d Date: Thu, 08 May 2014 12:20:45 +0100 From: Peter Stephenson To: zsh-users@zsh.org Subject: Re: globbing in conditional expressions Message-id: <20140508122045.3c68c3fa@pwslap01u.europe.root.pri> In-reply-to: <20140508105522.GE2052@tarsus.local2> References: <20140507124101.GA53652@isis.sigpipe.cz> <20140507154407.660eb500@pwslap01u.europe.root.pri> <20140508105522.GE2052@tarsus.local2> Organization: Samsung Cambridge Solution Centre X-Mailer: Claws Mail 3.7.9 (GTK+ 2.22.0; i386-redhat-linux-gnu) MIME-version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFuplluLIzCtJLcpLzFFi42I5/e/4Vd2+jOxgg7kfJSx2nFzJ6MDoserg B6YAxigum5TUnMyy1CJ9uwSujOfXHjAXfGWr+LbkO3sD417WLkZODgkBE4lLSw+yQdhiEhfu rQeyuTiEBJYySszumsQI5TABOW8YQapYBFQlnjZsZAex2QQMJaZumg0WFxEQlVi+YjNYXFjA QOLulfksIDavgL3E4peTgWwODk4BI4n/v6wgZk5ilDi+/jAzSA2/gL7E1b+fmCCusJeYeeUM I0SvoMSPyffA5jALaEls3tbECmHLS2xe85Z5AqPALCRls5CUzUJStoCReRWjaGppckFxUnqu kV5xYm5xaV66XnJ+7iZGSBB+3cG49JjVIUYBDkYlHt4FMhnBQqyJZcWVuYcYJTiYlUR4p6Zl BwvxpiRWVqUW5ccXleakFh9iZOLglGpg3Bbm/cwj+lLB+7Z21qo7K3epBzerunzax3PskO4S ZhWxJwtdT/rcf2oa2Xo84+jVu0pNPhHrzKxY34qan13iuWBm0zaNjKSJ81mt2ROnPfyfmCG7 55jBGsFf21deblDl092wTK/Fl/XNsraIDIdVmu9evVr1dkdWW/KUxc+Dfhf48724LsK3SIml OCPRUIu5qDgRAK0CbkIgAgAA On Thu, 08 May 2014 10:55:22 +0000 Daniel Shahaf wrote: > Peter Stephenson wrote on Wed, May 07, 2014 at 15:44:07 +0100: > > matches=(fubar(N/F)) > > [[ -z $matches ]] > > 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? > > This matters when the glob is matched against a large number of files. No, unless someone remembers I feature I don't know about, because internally the glob proceeds until it's finished --- so even if you use ([1]) to select the first match, the glob has already generated all matches at that point. If you have multiple different patterns, you can do it by writing a function to loop over them and return on the first match, but for a single pattern I think you're stuck. pws