Shell history

Kenneth Almquist ka at hropus.UUCP
Tue Mar 18 01:52:54 AEST 1986


> Old shell scripts ran successfully with the Bourne shell, which is why
> he could get away with replacing the old shell completely.

Actually, they generally didn't.  I'll give an example of a pre-Bourne
shell script for those of you who are curious:

	/bin/if $1x = x /bin/goto usage
	[commands to do actual work go here]
	/bin/exit
	: usage
	/bin/echo "Usage: command filename"
	/bin/exit 1

Several commands here no longer exist.  The program /bin/if evaluated
conditional expressions.  The expression "$1x = x" tests whether $1
is the null string.  (This looks like a silly way to do this, I know.
I think that the reason it was done this way is that $1 would not be
expanded if it was enclosed in quotes.)  If the expression evaluated
to true, /bin/if would execute the specified program:  /bin/goto in
this case.

/bin/goto performs a goto, just like its name implies.  The implemen-
tation of /bin/goto depended upon the fact that the shell read shell
scripts on file descriptor 0 using unbuffered reads.  The /bin/goto
program would seek to the beginning of the script and read forward
until it came to the specified label, which appeared on a line begin-
ning with a ":".  The ":" command does nothing; it was actually a
shell builtin even at this early date.

/bin/exit was a very simple program.  It just seeked to the end of
file on its standard input.  The second example worked because sh
would use (and still uses) the exit status of the last command invoked
as its exit status, so "/bin/exit 1" would seek to the end of file and
then exit with status of 1, which would cause the shell to terminate
with the same status.

Needless to say, all this broke with the Borne shell, which didn't
read shell scripts on the standard input.  One reason that the Borne
shell was accepted as a replacement for the old shell is that in a
shell script of any size the gotos became unreadable.  The big change
in converting to the Borne shell consisted of replacing all the gotos
with structured flow of control statements, which was obviously a
worthwhile enterprise even if the Borne shell had not required it.
				Kenneth Almquist
				ihnp4!houxm!hropus!ka	(official name)
				ihnp4!opus!ka		(shorter path)



More information about the Comp.unix.wizards mailing list