question-- Bourne (and C) SHELL

Daniel R. Levy levy at ttrdc.UUCP
Mon Aug 18 04:31:50 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

To follow your example literally:

ls foo
if test $? -ne 0	# or, "if [ $? -ne 0 ]" is supported by modern /bin/sh's
then
	echo foo does not exist
fi

Of course, there are other ways to check for nonexistence of foo, e.g.:

if [ ! -f foo -a ! -d foo -a ! -p foo -a ! -c foo -a ! -b foo ]

# foo is not a file, a directory, a pipe, a character special device, or a
# block special device

which though "wordier" does not require the spawning of another process
presuming that "test" is a builtin in your shell.
-- 
 -------------------------------    Disclaimer:  The views contained herein are
|       dan levy | yvel nad      |  my own and are not at all those of my em-
|         an engihacker @        |  ployer or the administrator of any computer
| at&t computer systems division |  upon which I may hack.
|        skokie, illinois        |
 --------------------------------   Path: ..!{akgua,homxb,ihnp4,ltuxa,mvuxa,
	   go for it!  			allegra,ulysses,vax135}!ttrdc!levy



More information about the Comp.unix.wizards mailing list