Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Globbing inside conditional expression
- X-seq: zsh-users 14893
- From: Ben North <ben@xxxxxxxxxxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: Re: Globbing inside conditional expression
- Date: Fri, 26 Feb 2010 12:56:12 +0000
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
Peter Stephenson, Fri, 26 Feb 2010 10:54:50:
> Ben North wrote:
> > > Actually [[ -f XX* ]] is invalid because [[ ]] doesn't do globbing.
> > > You need the [ -f XX* ] form (see below).
> >
> > answering my question. Apologies for the noise.
> > Perhaps the documentation could be clarified though?
> [...]
> I suppose it's obvious, but globbing would produce multiple files, and then
> a lot of the tests don't really make sense. What does [[ -d XX* ]] mean if
> some expansions are directories and some aren't?
My original situation was exactly the "how do I test whether any files
exist matching some glob pattern" which turned out to have been
discussed here 12--13 Feb. I read "the result of each expansion is
constrained to be a single word" in the man page and thought "OK, I
better make sure that at most one file results from the globbing,
otherwise it'll test for the existence of 'foo.1 foo.2'". I then tried
[[ -f foo.*(N[1]) ]]
and found it didn't do what I expected, so cut it down to the example I
originally posted.
I suppose the answer to your question about [[ -d XX* ]] would be 'it
returns false', if more than one expansion results. The test would be
of a non-existent file/directory like 'XX1 XX2 XX3'. But this would be
potentially confusing, certainly.
Your patch to the documentation clears things up, anyway. Thanks for
your time.
Ben.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author