How do I ask "if NOT" in shell?
Maarten Litmaath
maart at cs.vu.nl
Tue Oct 24 04:38:43 AEST 1989
kirkaas at oahu.cs.ucla.edu (paul kirkaas) writes:
\How can one say "if not" in a shellscript; that is, execute the body of
\the "then" only if the argument of "if" returns a non-zero exit status?
Unfortunately there doesn't seem to be a clean way to do this.
The obvious work-around:
if command
then
:
else
command
fi
A cleaner approach:
if not command
then
command
fi
...where `not' is defined as the following shell function/script:
${1+"$@"}
test $? != 0
SunOS 4.0.3c /bin/sh doesn't like a function to be named `!', a shell
script would be OK though.
--
A symbolic link is a POINTER to a file, | Maarten Litmaath @ VU Amsterdam:
a hard link is the file system's GOTO. | maart at cs.vu.nl, mcsun!botter!maart
More information about the Comp.unix.questions
mailing list