Negative if in Bourne (and C) SHELL

a.reed hfavr at mtuxo.UUCP
Mon Aug 18 10:01:02 AEST 1986


> Here's something I've wanted to do for a while but I can't seem to find the
> way to do it.
> 
> In the csh you can do something like
> 
> ls foo
> if (! $status) then
>    echo "foo exists"
> endif
> 
> The  key  thing  here  is  the  ability  to NOT the value of status. How is
> this similar thing done in Bourne shell.
> 
> if ! ls foo
> then
> 	echo foo does not exist
> fi
> 
> In  summary,  how can I take the logical NOT of a command's return value in
> the Bourne shell (which is God's gift to U**X :-)?
> -- 
> "Life is but a dream" - Lope de Vega
>     "...for some and a NIGHTMARE for others!" Merlin, "Excalibur", the movie
> Disclaimer?  What disclaimer?  I can back everything up with as much 
> drivel as you like!

Use "else", i.e.:

if ls foo
	then
		echo '\c'
	else
		echo foo does not exist
	fi
					Adam Reed (ihnp4!npois!adam)



More information about the Comp.unix.wizards mailing list