Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 14 Jul 2008 14:47:02 -0500
From:      Peter da Silva <peter@taronga.com>
To:        doc@FreeBSD.org
Subject:   The origin of the "#!" hack and selecting the shell
Message-ID:  <3046E1F6-F847-4A6E-953F-7FDD6F50CBE9@taronga.com>

next in thread | raw e-mail | index | archive | help
In <url:http://www.freebsd.org/doc/en/books/handbook/linuxemu- 
advanced.html> I read:

"Later, a hack was made for sh(1) to examine the first two  
characters, and if they were :\n, then it invoked the csh(1) shell  
instead (we believe SCO first made this hack)."

I'm pretty sure that nobody ever used ":\n" to indicate the C shell.

This hack originated at Berkeley, when the current version of UNIX  
was still V6. Before the Berkeley psh (Pascal shell) and csh (C  
shell) were developed, there wasn't any need for these hacks... there  
was only one shell and it was /bin/sh.

The V6 shell used the ":" (label) command for comments, while csh  
used "#". The first character of the file was checked by csh(1) and  
if it was a pound sign it used csh to run the script, otherwise it  
defaulted to the bourne shell. The "#!" hack (treating the string  
"#!" as a 16-bit magic number) came later, and was derived from this  
hack.

At one point a Comp Center admin (I won't mention who) went through  
all the shell scripts on all the Comp Center machines and made them  
start with a copyright notice that looked something like "# Copyright  
(C) YYYY Regents of the University of California" which had the  
effect of breaking all the scripts for anyone who was using the C shell.

Anyway, this was all happening in 1978 and 1979, and the first Xenix  
ports didn't start sneaking out until 1982, so it's unlikely that SCO  
had done anything like this first. :)



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3046E1F6-F847-4A6E-953F-7FDD6F50CBE9>