Shell Scripts v. Command Options

John F Haugh II jfh at rpp386.cactus.org
Sun Jan 20 06:21:54 AEST 1991


In article <1991Jan16.175908.3338 at zoo.toronto.edu> henry at zoo.toronto.edu (Henry Spencer) writes:
>Only if your users can type at least one command a second, which is rare.
>I have no idea what the fork rate on our system is -- although being a Sun,
>it's probably damnably slow -- but it's enough for our not-notably-patient
>user community.  A user who's sitting in a text editor or waiting for a
>sort to finish doesn't care about the fork rate.  A user who's running
>"who" or a variant thereon usually doesn't either.

Actually it is quite easy for a user to exceed one command per second.
This is done most easily by writing shell scripts, since each execution
of the shell script will involve many more commands being executed.  The
overhead of fork/exec in those cases is completely wasted.

There are some obvious places where scripts are warranted - such as where
the execution time of the commands being executed dominates the execution
time of the shell.  In the case of short lived commands, such as "who |
wc -l" it may be questionable - the command doesn't run very long in
either case.  A more ridiculous example might be where "who -q" is
implemented somewhat faithfully as a shell script.

--
if [ $# != 0 ]; then
	INPUT=$1
else
	INPUT=/etc/utmp
fi
USERS=`who $INPUT | cut -d' ' -f1`
LINE=0
for USER in $USERS; do
	LENGTH=`expr $USER : '.*'`
	if [ `expr $LENGTH + $LINE + 1` -gt 80 ]; then
		LINE=0
		echo
	fi
	LINE=`expr $LINE + $LENGTH + 1`
	echo $USER '\c'
done
echo
COUNT=`who $INPUT | wc -l | sed -e 's/ *//g'`
echo '# users='$COUNT
--

Yes, it is an absolutely absurd example and is intended only to
illustrate how incredibly SLOW shell scripts can be compared to the
options when implemented in C code.
-- 
John F. Haugh II                             UUCP: ...!cs.utexas.edu!rpp386!jfh
Ma Bell: (512) 832-8832                           Domain: jfh at rpp386.cactus.org
"While you are here, your wives and girlfriends are dating handsome American
 movie and TV stars. Stars like Tom Selleck, Bruce Willis, and Bart Simpson."



More information about the Comp.bugs.sys5 mailing list