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

Re: globbing in conditional expressions

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:

  # 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.

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