home *** CD-ROM | disk | FTP | other *** search
- 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
- From: bnb@ukc.ac.uk (B.N.Blackmore)
- Newsgroups: comp.unix.shell
- Subject: Re: if syntax
- Keywords: if, csh
- Message-ID: <6430@falcon.ukc.ac.uk>
- Date: 6 Nov 92 13:58:05 GMT
- References: <1992Nov5.230024.14504@u.washington.edu>
- Reply-To: bnb@ukc.ac.uk (The Impossible Dreamer)
- Organization: Computing Lab, University of Kent at Canterbury, UK.
- Lines: 40
- Nntp-Posting-Host: falcon.ukc.ac.uk
-
- In article <1992Nov5.230024.14504@u.washington.edu> micah@carson.u.washington.edu (Micah Anderson) writes:
- :Am I stupid or what? I cannot figger out why the hell this does this...
- :I made a simple script (in order to demonstrate a harder problem...)
- :
- :#! /bin/csh -f
- :if test -s testes then
- : echo "yes"
- :endif
- :end
- :when I try to run it I get:
- :if: Expression syntax.
- :what the hell do I do? I have been beating my brains out over this simple
- :friggin' thing...
-
- The reason you are getting that error is because the 'if' statement in the
- C-Shell acts on an expression as oppossed to the exit status of the enclosed
- command (as in the bourne shell), several operators are available which allow
- you to test for files, but this is not as flexible as the bourne shell way of
- doing it. If you still need to write this in C-Shell the following should do
- what you require. (no bets on it though)
-
- #! /bin/csh
-
- if ((-e testes)&&(!(-z testes))) then
- echo "yes"
- endif
-
- You can probably remove some of the brackets. A better idea though would be
- to program it in the bourne shell (or something compable with it) using...
-
- #! /bin/sh
-
- if test -s testes
- then
- echo yes
- fi
-
- --
- Brian Blackmore, Darwin College, The University of Kent at Canterbury.
- Vee Eye, They called it a programmers editor, I'd rather program a new one.
-