home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.unix.questions
- Path: sparky!uunet!haven.umd.edu!darwin.sura.net!news.udel.edu!udel!princeton!fish.Princeton.EDU!lhjensen
- From: lhjensen@fish.Princeton.EDU (Leif Jensen)
- Subject: Re: failure by negation
- Message-ID: <1992Dec13.052353.16456@Princeton.EDU>
- Originator: news@nimaster
- Sender: news@Princeton.EDU (USENET News System)
- Nntp-Posting-Host: fish.princeton.edu
- Organization: Princeton University
- References: <1gdn6pINNe0d@darkstar.UCSC.EDU> <naam.724198325@terra.cecer.army.mil>
- Date: Sun, 13 Dec 1992 05:23:53 GMT
- Lines: 35
-
- In article <naam.724198325@terra.cecer.army.mil> naam@cecer.army.mil (Ramez Naam) writes:
- >gil@cse.ucsc.edu (Elmer Fudd) writes:
- >>the following c shell program does the opposite of what i want,
- >>it checks to see that a file "alive.n.well" exists, then it stops
- >>execution, i want it to do the same if the file doesn't exists!
- >>how do i do it?
- >>test -f alive.n.well && exit
- >test -f [ ! alive.n.well ] && exit
-
- I think Ramez confused two different things. The answer he gives
- doesn't work. (Is it so hard to test something so simple before
- posting or is this just a case of a major typo?) Since the original
- poster had a csh script, there are several obvious possibilities.
-
- test -f alive.n.well || exit
- test \! -f alive.n.well && exit
- if (! -f alive.n.well) exit
-
- On many platforms [ is just a link to test, and when test's argv[0] is
- "[" it checks that its last argument is "]", so the following two lines
- may also work:
-
- [ -f alive.n.well ] || exit
- [ \! -f alive.n.well ] && exit
-
- Notice that the space after "[" is essential. Many Bourne shells
- have [ built-in since it is used so much. Actually, I would recommend
- to the original poster that he practice scripting with /bin/sh instead
- of with /bin/csh.
-
- Hope this helps,
-
- --
- Leif Jensen
- lhjensen@phoenix.princeton.edu
-