Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: FAQ : how to check for existence of a file ABC*
- X-seq: zsh-users 14830
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: jarausch@xxxxxxxxxxxxxxxxxxx
- Subject: Re: FAQ : how to check for existence of a file ABC*
- Date: Fri, 12 Feb 2010 08:51:34 -0800
- Cc: zsh-users@xxxxxxx
- In-reply-to: <87vde2zn07.fsf@xxxxxxxxxxxxxxxxxxxxxx>
- 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
- References: <tkrat.d1856a3e314a4383@xxxxxxxxxxxxxxxxxxx> <87vde2zn07.fsf@xxxxxxxxxxxxxxxxxxxxxx>
On Feb 12, 12:55pm, Frank Terbeck wrote:
} Subject: Re: FAQ : how to check for existence of a file ABC*
}
} Helmut Jarausch wrote:
} > if NULL_GLOB is unset the shell bails out if no such file exists;
} > but if NULL_GLOB is set, then the test [[ -f XX* ]] is invalid since
} > XX* expands to a null string.
Actually [[ -f XX* ]] is invalid because [[ ]] doesn't do globbing.
You need the [ -f XX* ] form (see below).
} And if you don't want to introduce a function, you may want to use
} something along the lines of this:
} <http://www.zsh.org/mla/users/2009/msg00512.html>
I'm not sure why I didn't suggest this back in that earlier thread,
but what you really want is NO_NOMATCH not NULL_GLOB. (Unfortunately
there's no glob qualifier to turn on the former, or to turn *off*
CSH_NULL_GLOB which you also need to do.)
The other tricky bit is that [ -f XX* ] will fail if XX* expands to
more than one file, so you need to use the subscript glob qualifier
to be sure you pick off only one of those files: XX*([1])
Fortunatly recent zsh now has inline functions:
if (){ setopt localoptions nonomatch nocshnullglob; [ -f XX*([1]) ] }
then
...
fi
You might need to throw some other options into that setopt, like
nonullglob as well, to make it universal.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author