Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: [[ -f file* ]]
- X-seq: zsh-users 14134
- From: Peter Stephenson <pws@xxxxxxx>
- To: zsh-users@xxxxxxxxxx
- Subject: Re: [[ -f file* ]]
- Date: Mon, 18 May 2009 10:55:39 +0100
- In-reply-to: <17393e3e0905180236v424b14d5ua9d364501662c75a@xxxxxxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- Organization: CSR
- References: <20090518091455.83279.qmail@xxxxxxxxxxx> <17393e3e0905180236v424b14d5ua9d364501662c75a@xxxxxxxxxxxxxx>
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