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

Re: Globbing inside conditional expression



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