question-- Bourne (and C) SHELL

Guy Harris guy at sun.uucp
Sat Aug 16 08:27:59 AEST 1986


> 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.
-- 
	Guy Harris
	{ihnp4, decvax, seismo, decwrl, ...}!sun!guy
	guy at sun.com (or guy at sun.arpa)



More information about the Comp.unix.wizards mailing list