home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / unix / shell / 4575 < prev    next >
Encoding:
Internet Message Format  |  1992-11-07  |  1.8 KB

  1. Path: sparky!uunet!cis.ohio-state.edu!zaphod.mps.ohio-state.edu!darwin.sura.net!paladin.american.edu!news.univie.ac.at!hp4at!mcsun!uknet!rook.ukc.ac.uk!falcon.ukc.ac.uk!bnb
  2. From: bnb@ukc.ac.uk (B.N.Blackmore)
  3. Newsgroups: comp.unix.shell
  4. Subject: Re: if syntax
  5. Keywords: if, csh
  6. Message-ID: <6430@falcon.ukc.ac.uk>
  7. Date: 6 Nov 92 13:58:05 GMT
  8. References: <1992Nov5.230024.14504@u.washington.edu>
  9. Reply-To: bnb@ukc.ac.uk (The Impossible Dreamer)
  10. Organization: Computing Lab, University of Kent at Canterbury, UK.
  11. Lines: 40
  12. Nntp-Posting-Host: falcon.ukc.ac.uk
  13.  
  14. In article <1992Nov5.230024.14504@u.washington.edu> micah@carson.u.washington.edu (Micah Anderson) writes:
  15. :Am I stupid or what? I cannot figger out why the hell this does this...
  16. :I made a simple script (in order to demonstrate a harder problem...)
  17. :
  18. :#! /bin/csh -f
  19. :if test -s testes then
  20. :          echo "yes"
  21. :endif
  22. :end
  23. :when I try to run it I get:
  24. :if: Expression syntax.
  25. :what the hell do I do? I have been beating my brains out over this simple
  26. :friggin' thing...
  27.  
  28. The reason you are getting that error is because the 'if' statement in the
  29. C-Shell acts on an expression as oppossed to the exit status of the enclosed
  30. command (as in the bourne shell), several operators are available which allow
  31. you to test for files, but this is not as flexible as the bourne shell way of
  32. doing it. If you still need to write this in C-Shell the following should do
  33. what you require. (no bets on it though)
  34.  
  35. #! /bin/csh
  36.  
  37. if ((-e testes)&&(!(-z testes))) then
  38.     echo "yes"
  39. endif
  40.  
  41. You can probably remove some of the brackets. A better idea though would be
  42. to program it in the bourne shell (or something compable with it) using...
  43.  
  44. #! /bin/sh
  45.  
  46. if test -s testes
  47. then
  48.     echo yes
  49. fi
  50.  
  51. --
  52. Brian Blackmore, Darwin College, The University of Kent at Canterbury.
  53. Vee Eye, They called it a programmers editor, I'd rather program a new one.
  54.