foreach: No match
Jonathan I. Kamens
jik at athena.mit.edu
Wed Apr 17 19:46:18 AEST 1991
In article <9104161842.AA13587 at tea-jwm.jhuapl.edu>, jwm at SUN4.JHUAPL.EDU (James W. Meritt) writes:
|> The irritating thing is that when there isn't anything in the
|> directory, I get the subject error message on the console. I don't
|> WANT an error message. How do I stop this?
>From csh(1):
nonomatch If set, it is not an error for a filename
expansion to not match any existing files;
rather the primitive pattern is returned. It
is still an error for the primitive pattern
to be malformed, i.e. `echo [' still gives
an error.
For example:
% mkdir empty
% cd empty
% set files = *
set: No match.
% set nonomatch
% set files = *
% echo $files
*
%
You use this in your script like this:
set nonomatch
set files = *
unset nonomatch
if ("$files" == "*") then
# Whatever you would do if there are no files to process, like
# perhaps exiting
else
foreach file ($files)
# the body of your foreach
end
endif
I think the idea is clear.
--
Jonathan Kamens USnail:
MIT Project Athena 11 Ashford Terrace
jik at Athena.MIT.EDU Allston, MA 02134
Office: 617-253-8085 Home: 617-782-0710
More information about the Comp.unix.questions
mailing list