[comp.os.minix] exec of shell scripts

dprrhb@inetg1.ARCO.COM (Reginald H. Beardsley) (05/04/91)

 POSIX skirts the issue of how to handle shell scripts and #!.  I 
can think of no instance where implementing #! interpretation in 
the kernel exec code would break anything that one would reasonably
want to do. (ie.  the shell could still interpret #! and not use the
functionality in the kernel if it so chose)  This leads me to the 
conclusion that placing #! in the kernel is appropriate.

From p. 228 of ISO/IEC 9945-1: 1990 (IEEE 1003.1)

  Some systems can exec shell scripts.  This functionality is outside 
the scope of POSIX.1, since it requires standardization of the command
interpreter language of the script and/or where to find a command 
interpreter. These fall in the domain of the shell and utilities
standard, currently under development as ISO/IEC 9945-2. However, it 
is important that POSIX.1 neither require nor preclude any reasonable 
implementation of this behavior.  In particular, the description of
the [ENOEXEC] error is intended to permit discretion to implementations
on whether to give this error for shell scripts.

One common historical implementation is that the execl(), execv(), 
execle(), and execve() functions return an [ENOEXEC] error for any file 
not recognizable as executable, including a shell script.  When the 
execlp() and execvp() functions encounter such a file, they assume the 
file to be a shell script and invoke a known command interpreter to 
interpret such files.  These implementations of execvp() and execlp() 
only give the [ENOEXEC[ error in the rare case of a problem with the
command interpreter's executable file.  Because of these 
implementations the [ENOEXEC] error is not mentioned for execlp() or 
execvp(), although implementations can still give it.

Another way that some historical implementaions handle shell scripts 
is by recognizing the first two bytes of the file as the character 
string #! and using the remainder of the first line of the file as 
the name of the command interpreter to execute.



-- 
Reginald H. Beardsley       
ARCO Information Services
Plano, TX 75075           
Phone: (214)-754-6785
Internet: dprrhb@arco.com