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

Re: [[ -f file* ]]



On Mon, 18 May 2009 05:36:18 -0400
Matt Wozniski <godlygeek@xxxxxxxxx> wrote:
> On Mon, May 18, 2009 at 5:14 AM, Atom Smasher wrote:
> > if i want to test for the presence of one or more files matching a certain
> > pattern, it seems non-trivial to do it with the normal "test" or conditional
> > expressions.
> ...
> > is there a better way?
> 
> Well, off the top of my head, I can think of
> 
> [ -n "$(print -- test*(N))" ]
> 
> but even that seems inelegant; I'm sure someone can chime in with
> something better.

has_matches() {
  (( $# > 0 ))
}

if has_matches test*(N); then
  # some matches
else
  # no matches
fi


You need to remember the (N).  There are ways around that.

-- 
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070



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