Why is Berkeley "head" a program?
Larry Tepper
lat at stcvax.UUCP
Fri Oct 12 04:00:46 AEST 1984
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-5435
More information about the Comp.unix
mailing list