question-- Bourne (and C) SHELL
Steven Augart
swa at COMET.LCS.MIT.EDU
Fri Aug 22 06:47:20 AEST 1986
From: Arturo Perez <arturo%humming.uucp at BRL.ARPA>
Date: 14 Aug 86 14:12:45 GMT
In the csh you can do something like
ls foo
if (! $status) then
echo "foo exists"
endif
(parenthetical note: "ls" will return status 0 whether or not it can
find foo. The example is faulty).
The key thing here is the ability to NOT the value of status. How is
this similar thing done in Bourne shell.
Can't be done directly in the Bourne shell, since the Bourne shell
simply doesn't have C-shell style expressions; they are handled
separately by the "test" and "expr" programs. Since the bourne shell
doesn't have expressions, it also doesn't have an internal NOT
operator.
However, you can do this simple workaround (or you could if "ls foo"
returned 0 status to indicate that it found "foo" and nonzero status
to indicate that it hadn't found "foo"):
if ls foo
then
;
else
echo "foo not found"
endif
Steven Augart
MIT Laboratory for Computer Science
swa at xx.lcs.mit.edu, swa at xx.ARPA
More information about the Comp.unix.wizards
mailing list