The origin of the "#!" hack and selecting the shell

Peter da Silva peter at taronga.com
Tue Jul 15 01:23:51 UTC 2008


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. :)



More information about the freebsd-doc mailing list