question-- Bourne (and C) SHELL

Jonathan Hahn hahn at ames-prandtl.arpa
Sat Aug 23 08:17:54 AEST 1986


In article <150 at humming.UUCP>, arturo at humming.UUCP (Arturo Perez) writes:
>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

I haven't seen any mention of our Bourne shell friend "||".  How about
(assuming ls returns correct status):

	ls foo || echo foo does not exist

If you want to get rid of the output and error messages from ls:

	ls foo > /dev/null 2>&1 || echo foo does not exist

And if you want a complex second statement:

	ls foo || {
		echo foo does not exist
		exit
	}

-jonathan hahn
NAS Program, Ames Research Center
Moffett Field, CA
hahn at ames-nas



More information about the Comp.unix.wizards mailing list