How do I ask "if NOT" in shell?

Gunter Steinbach steinbac at hpl-opus.HP.COM
Fri Oct 27 03:32:11 AEST 1989


>From article <1989Oct26.041244.28325 at sobmips.UUCP>, by roe at sobmips.UUCP
(r.peterson):
> I tried this:
> true && {
> 	echo true
> } || {
> 	echo false
> }
> and it functions fine.  Change true && to false && and it prints false
> correctly as well.

Neato!  I like it.  
But...  You have to be careful with nontrivial commands in the first
command group (the if true group):  Add a "false" command after the
first echo in your example, and it prints out both "true" and "false" -
not at all what you wanted.

So it is not a true "else" that only refers to the original test.

	 Guenter Steinbach	 |	 hplabs!gunter_steinbach
				 |	 gunter_steinbach at hplabs.hp.com



More information about the Comp.unix.questions mailing list