Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10 5/3/83; site stcvax.UUCP
Path: utzoo!linus!philabs!cmcl2!seismo!hao!stcvax!lat
From: lat@stcvax.UUCP (Larry Tepper)
Newsgroups: net.unix
Subject: Why is Berkeley "head" a program?
Message-ID: <312@stcvax.UUCP>
Date: Thu, 11-Oct-84 14:00:46 EDT
Article-I.D.: stcvax.312
Posted: Thu Oct 11 14:00:46 1984
Date-Received: Sat, 13-Oct-84 01:41:50 EDT
Organization: Storage Technology Corp.  Louisville, CO
Lines: 46

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