question-- Bourne (and C) SHELL

Steve Alesch sja at ih1ap.UUCP
Fri Sep 12 13:38:56 AEST 1986


In article <6228 at sun.uucp>, guy at sun.uucp (Guy Harris) writes:
> > 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
> 
> Try
> 
> 	if ls foo
> 	then
> 		:
> 	else
> 		echo foo does not exist
> 	fi
> 
> The ":"  is the pseudo-comment from old Bourne shells; it's really a command
> that does nothing.
> 
> Not the cleanest syntax, but that's life.  (However, I'd rather have a shell
> that requires that crud, but allows you to redirect the output of a "for"
> loop, than one that permits you to negate exit status directly but won't let
> you redirect the output of loops!  At least with the Bourne shell you can
> get around the inability to negate exit status fairly easily.)
> 
> However, you may be better off doing
> 
> 	if test ! -f foo
> 
> or something like that; unfortunately, "test" doesn't have a predicate for
> "just test whether it exists", but you may really want a more restrictive
> predicate anyway.

Correct me if I'm missing something.  What's wrong with:

	ls foo
	if [ $? != 0 ]; then
		echo foo does not exist
	fi
-- 

Steve Alesch	AT&T
(312)510-7881, ...!ihnp4!ih1ap!sja



More information about the Comp.unix.wizards mailing list