Subject: Re: a suggestion for improving shell behaviour....
To: NetBSD Userlevel Technical Discussion List <tech-userlevel@netbsd.org>
From: Erik E. Fair <fair@clock.org>
List: tech-userlevel
Date: 02/18/1999 13:46:38
One upon a time, there were executable files containing machine code(i.e.
a.out files), and one shell, Bourne. The Bourne shell would attempt to
exec(2) a command, and if that failed, it would open up the file and
attempt to interpret it as a shell script.
Then came the C shell, which kinda did the same thing, except that if the
shell script contained ":" as a comment delimiter, csh would exec sh to
interpret the script. However, this hack left a problem: how do sh users
make csh scripts work without hacking the sh to somehow recognize csh
scripts? This becomes a nasty M x N problem as the number of shells
increase.
Then, some bright person suggested the correct solution: the kernel should
recognize scripts with the right sort of line at the top of the file, and
exec the correct interpreter. Thus was #!/bin/foo invented.
Given this state of affairs, the code in each shell to recognize scripts
should be excised, and they should simply execve(2) commands, as originally
intended. Scripts without the interpreter magic will fail, the kernel will
not exec binaries for the wrong architectures, and all will be well.
Erik <fair@clock.org>