* Re: [[ -f file* ]]
2009-05-18 9:36 ` Matt Wozniski
@ 2009-05-18 9:55 ` Peter Stephenson
2009-05-18 11:35 ` Atom Smasher
2009-05-18 11:40 ` Frank Terbeck
2 siblings, 0 replies; 5+ messages in thread
From: Peter Stephenson @ 2009-05-18 9:55 UTC (permalink / raw)
To: zsh-users
On Mon, 18 May 2009 05:36:18 -0400
Matt Wozniski <godlygeek@gmail.com> 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@csr.com> Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [[ -f file* ]]
2009-05-18 9:36 ` Matt Wozniski
2009-05-18 9:55 ` Peter Stephenson
@ 2009-05-18 11:35 ` Atom Smasher
2009-05-18 11:40 ` Frank Terbeck
2 siblings, 0 replies; 5+ messages in thread
From: Atom Smasher @ 2009-05-18 11:35 UTC (permalink / raw)
To: zsh-users
On Mon, 18 May 2009, Matt Wozniski wrote:
> 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.
=================
it's less inelegant than my original method ;)
and it works fine with '[[' conditional expressions... which, IIUC, is the
"new and improved" version of test.
--
...atom
________________________
http://atom.smasher.org/
762A 3B98 A3C3 96C9 C6B7 582A B88D 52E4 D9F5 7808
-------------------------------------------------
"In every respect, vegans appear to enjoy equal
or better health in comparison to both vegetarians
and non-vegetarians."
-- T. Colin Campbell,
PhD Professor of Nutrition, Cornell University
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [[ -f file* ]]
2009-05-18 9:36 ` Matt Wozniski
2009-05-18 9:55 ` Peter Stephenson
2009-05-18 11:35 ` Atom Smasher
@ 2009-05-18 11:40 ` Frank Terbeck
2 siblings, 0 replies; 5+ messages in thread
From: Frank Terbeck @ 2009-05-18 11:40 UTC (permalink / raw)
To: zsh-users
Matt Wozniski <godlygeek@gmail.com>:
> 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.
How about this:
[snip]
set -- test*(N)
(( $# > 0 ))
[snap]
Regards, Frank
--
In protocol design, perfection has been reached not when there is
nothing left to add, but when there is nothing left to take away.
-- RFC 1925
^ permalink raw reply [flat|nested] 5+ messages in thread