How do I ask "if NOT" in shell?

Randal Schwartz merlyn at iwarp.intel.com
Tue Oct 24 06:18:58 AEST 1989


In article <28381 at shemp.CS.UCLA.EDU>, kirkaas at oahu (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?
| 
| I would like something like:
| 
| if ! TESTCOMMAND
| then
| 	BODY
| fi
| 
| Stupid question?   Trivial answer?   I hope so.  Thanks.

Yeah.

if TESTCOMMAND
then
	: nada
else
	BODY
fi

Easy.

Just another Bourne-again hacker,
-- 
/== Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ====\
| on contract to Intel's iWarp project, Hillsboro, Oregon, USA, Sol III  |
| merlyn at iwarp.intel.com ...!uunet!iwarp.intel.com!merlyn	         |
\== Cute Quote: "Welcome to Oregon... Home of the California Raisins!" ==/



More information about the Comp.unix.questions mailing list