🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.bugs.sys5
Article #319

Re: Shell Scripts v. Command Options

#319
From: John F Haugh II
Date: Sat, 19 Jan 1991 19:21
50 lines
2679 bytes
In article <1991Jan16.175908.3338@zoo.toronto.edu> henry@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@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."
Technical Details
Message-ID: <18964@rpp386.cactus.org>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!watserv1!watmath!att!tut.cis.ohio-state.edu!cs.utexas.edu!execu!sequoia!rpp386!jfh
References: <18899@rpp386.cactus.org> <1991Jan14.202053.20054@zoo.toronto.edu> <18946@rpp386.cactus.org> <1991Jan16.175908.3338@zoo.toronto.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!watserv1!watmath!att!tut.cis.ohio-state.edu!cs.utexas.edu!execu!sequoia!rpp386!jfh
From: jfh@rpp386.cactus.org (John F Haugh II)
Newsgroups: comp.bugs.sys5
Subject: Re: Shell Scripts v. Command Options
Message-ID: <18964@rpp386.cactus.org>
Date: 19 Jan 91 19:21:54 GMT
References: <18899@rpp386.cactus.org> <1991Jan14.202053.20054@zoo.toronto.edu> <18946@rpp386.cactus.org> <1991Jan16.175908.3338@zoo.toronto.edu>
Reply-To: jfh@rpp386.cactus.org (John F Haugh II)
Organization: Lone Star Cafe and BBS Service
Lines: 50
X-Clever-Slogan: Recycle or Die.