WG15 Defect Report Ref: 9945-2-20
Topic: sh

This is an approved interpretation of 9945-2:1993.


Last update: 1997-05-20



	Topic:			sh
	Relevant Sections:, 4.56.4

Defect Report:
          In Section, the standard  defines  an  ``executable 
          file'' as ``a regular file acceptable as a new process image 
          by the equivalent of the POSIX.1 exec family of functions.'' 
          [Draft 12 of ISO/IEC 9945-2:1993 (July 1992), p. 21,  lines 
          In the definition of  PATH  in  Section  2.6  -  Environment 
          Variables, the standard states that ``[t]he  list  shall  be 
          searched from beginning to end  [...]  until  an  executable 
          file with  the  specified  name  and  appropriate  execution 
          permissions is found.''  [Ibid., p. 78, lines 2705-2708] 
          In Section  -  Command  Search  and  Execution,  the 
          standard describes the method for locating a simple command, 
          possibly ``using the PATH environment variable as  described 
          in 2.6,'' [Ibid., p. 141, lines 775-776], and then states: 
               If the execve() function fails  due  to  an  error 
               equivalent to the POSIX.1 {8} error [ENOEXEC], the 
               shell shall execute a command equivalent to having 
               a shell invoked with the command name as its first 
               operand, along with any remaining arguments passed 
               along.  If the executable file is not a text file, 
               the shell may bypass this command execution, write 
               an error message, and return  an  exit  status  of 
          [Ibid., p. 142, lines 787-794, and lines 810-815] 
          So, following the reference into Section 4.56.4  -  Operands 
          {of sh}, the standard states: 
               If  the  pathname  contains  one  or  more   slash 
               characters, the implementation  shall  attempt  to 
               read that file; the file need not  be  executable. 
               If  the  pathname  does  not   contain   a   slash 
               -    The implementation shall attempt to read that 
                    file from the current working directory;  the 
                    file need not be executable. 
          [Ibid., p. 437, lines 8907-8912] 
          Now, there is no requirement  in  POSIX.1  that  exec()  can 
          necessarily run shell  scripts  (using  the  #!  interpreter 
          convention). Thus, text files containing a list of  commands 
          to pass to  the  shell,  commonly  referred  to  as  ``shell 
          scripts,''  may  not  be  executable  according  to  Section 
  If a ``simple command,'' as  defined  in  Section 
  is  actually  a  shell  script,  it  will  not   be 
          executable, so it will be invoked as if  a  command_file  in 
          Section 4.56.4, even if its execution  permission  bits  are 
          not set.  Only Section 2.6 deals with the  permission  bits, 
          and then only for executable files. 
          To remedy this problem, can the phrase  ``executable  file'' 
          be interpreted in Sections 2.6,, and 4.56.4 as  also 
          including  shell  scripts  with  the   execute   bits   set? 
          Otherwise, shell scripts never need to  have  their  execute 
          bits set, contrary to historical practice. 

WG15 response for 9945-2:1993 

The standard clearly states the requirements for appropriate  execution
permissions and conforming implementations must conform to this.
If the appropriate execute permission bit is not set 
then the process image file does not have appropriate access

ISO/IEC 9945-1:1990 specifies the ENOEXEC error for the execve()
function as being returned if the file does have the
appropriate permissions but is not a process image, and the EACCESS
error as being returned if the file does not have the appropriate 

Hence if the file does not have the appropriate execute bit set
EACCESS is returned and no attempt to execute the file as a shell
script will result.

Rationale for Interpretation:

Recirculated for 30 day review: Oct 19 1995
Finalised: Nov 20 1995