question-- Bourne (and C) SHELL

Guy Harris guy at sun.uucp
Thu Sep 18 05:07:38 AEST 1986


> Correct me if I'm missing something.  What's wrong with:
> 
> 	ls foo
> 	if [ $? != 0 ]; then
> 		echo foo does not exist
> 	fi

It doesn't indicate quite as clearly as the other version that the
failure/success of "ls" is being tested.  It merely indicates that the exit
status of "ls" is being compared against 0; you have to associate this with
failure/success.  (See past discussions in net.lang.c about why Boolean
types exist even if you language happens to implement them as integral
types.)

In addition, 1) "ls" does not always return an exit status indicating
whether it could find the files in question or not and 2) "ls" *does* always
print the name of the file, if it finds it, or an error, if it doesn't.  If
"test" had a "does this file exist" predicate, then as I mentioned that
would be what you should use.
-- 
	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