lat@stcvax.UUCP (Larry Tepper) (10/11/84)
I'm tempted to post this to net.bugs.4bsd...
Call me naive if you wish, but why is /usr/ucb/head a program
and not a shell script? It was my understanding that with UNIX
you were supposed to build new tools based upon current ones,
and that the shell was also considered a programming language.
In addition, I foolishly thought that if a function is not used
FREQUENTLY, then the "overhead" of using a shell script was
considered acceptable. Perhaps there are people out there who
are head heads??? (Ouch! 8-)
I believe the following shell script is equivalent to /usr/ucb/head.
It could even be 5 lines shorter if, when presented with several
files, you were willing to accept an extra newline at the start of
the first one.
: head -- give the first few lines of a stream
count=10
case $1 in
-[0-9]*)
count=`echo $1 | sed s/-//`
shift
;;
esac
case $# in
0|1) sed ${count}q $1
exit $?
;;
esac
: first file is special
sed "1i\\
==> $1 <==
${count}q" $1
shift
for f in $*
do
sed "1i\\
\\
==> $f <==
${count}q" $f
done
--
Violence is the last refuge of the incompetent.
{ihnp4 hao philabs sdcrdcf ucbvax!nbires}!stcvax!lat Larry Tepper
Storage Technology, MD-3T, Louisville, CO 80028 303-673-5435rik@uf-csg.UUCP (Rik Faith [guest]) (10/29/84)
<> Certainly many current standard UN*X tools can be written as shell scripts. The disk memory overhead required to maintain a binary, however, seems minimal, especially on a system with lots of disk space, when compared with the time and process overhead of a shell script. The tools, as binaries, are truly shell independent, as I feel they should be: as a user of csh, I am constantly spawning sh processes to run shell-scripts that could have been written in C. -- Rik Faith, student at the University of Florida, Gainesville UUCP: ..!akgua!uf-csv!uf-csg!rik [Is not life a hundred times to short for us to bore ourselves? -F.N.]