Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!sdd.hp.com!think.com!mintaka!bloom-picayune.mit.edu!athena.mit.edu!jik From: jik@athena.mit.edu (Jonathan I. Kamens) Newsgroups: comp.unix.questions Subject: Re: foreach: No match Message-ID: <1991Apr17.094618.3466@athena.mit.edu> Date: 17 Apr 91 09:46:18 GMT References: <9104161842.AA13587@tea-jwm.jhuapl.edu> Sender: news@athena.mit.edu (News system) Organization: Massachusetts Institute of Technology Lines: 47 In article <9104161842.AA13587@tea-jwm.jhuapl.edu>, jwm@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@Athena.MIT.EDU Allston, MA 02134 Office: 617-253-8085 Home: 617-782-0710