Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: globbing in conditional expressions



On Thu, 08 May 2014 10:55:22 +0000
Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx> 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



Messages sorted by: Reverse Date, Date, Thread, Author