question-- Bourne (and C) SHELL
    anw at nott-cs.UUCP 
    anw at nott-cs.UUCP
       
    Wed Aug 20 21:05:54 AEST 1986
    
    
  
In article <6228 at sun.uucp> guy at sun.uucp (Guy Harris) writes:
>Try
>
>	if ls foo
>	then
>		:
>	else
>		echo foo does not exist
>	fi
Or you could try
	ls foo ||
	    echo foo does not exist
In complicated situations, "if ... then ... else ... fi" is clearer, but
where there is only one subsidiary command I think "&&" and "||" can tidy
up shell scripts quite a lot.  I often use (V7 with SV shell) something like
	[ -w foo ] || fault "can't write to foo"
where "fault" is a suitable function, such as
	fault () { echo $0: error, "$@" 1>&2; exit 1; }
						-- Andy Walker,
						     Maths Dept, Nottm Univ
    
    
More information about the Comp.unix.wizards
mailing list