home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / unix / question / 14644 < prev    next >
Encoding:
Text File  |  1992-12-13  |  1.8 KB  |  49 lines

  1. Newsgroups: comp.unix.questions
  2. Path: sparky!uunet!haven.umd.edu!darwin.sura.net!news.udel.edu!udel!princeton!fish.Princeton.EDU!lhjensen
  3. From: lhjensen@fish.Princeton.EDU (Leif Jensen)
  4. Subject: Re: failure by negation
  5. Message-ID: <1992Dec13.052353.16456@Princeton.EDU>
  6. Originator: news@nimaster
  7. Sender: news@Princeton.EDU (USENET News System)
  8. Nntp-Posting-Host: fish.princeton.edu
  9. Organization: Princeton University
  10. References: <1gdn6pINNe0d@darkstar.UCSC.EDU> <naam.724198325@terra.cecer.army.mil>
  11. Date: Sun, 13 Dec 1992 05:23:53 GMT
  12. Lines: 35
  13.  
  14. In article <naam.724198325@terra.cecer.army.mil> naam@cecer.army.mil (Ramez Naam) writes:
  15. >gil@cse.ucsc.edu (Elmer Fudd) writes:
  16. >>the following c shell program does the opposite of what i want,
  17. >>it checks to see that a file "alive.n.well" exists, then it stops
  18. >>execution, i want it to do the same if the file doesn't exists!
  19. >>how do i do it?
  20. >>test -f alive.n.well && exit
  21. >test -f [ ! alive.n.well ] && exit
  22.  
  23. I think Ramez confused two different things.  The answer he gives
  24. doesn't work.  (Is it so hard to test something so simple before
  25. posting or is this just a case of a major typo?) Since the original
  26. poster had a csh script, there are several obvious possibilities.
  27.  
  28. test -f alive.n.well || exit
  29. test \! -f alive.n.well && exit
  30. if (! -f alive.n.well) exit
  31.  
  32. On many platforms [ is just a link to test, and when test's argv[0] is
  33. "[" it checks that its last argument is "]", so the following two lines
  34. may also work:
  35.  
  36. [ -f alive.n.well ] || exit
  37. [ \! -f alive.n.well ] && exit
  38.  
  39. Notice that the space after "[" is essential.  Many Bourne shells
  40. have [ built-in since it is used so much.  Actually, I would recommend
  41. to the original poster that he practice scripting with /bin/sh instead
  42. of with /bin/csh.
  43.  
  44. Hope this helps,
  45.  
  46. --
  47. Leif Jensen
  48. lhjensen@phoenix.princeton.edu
  49.