Answering questions that may arise related to the meaning of portions of an IEEE standard concerning specific applications.

IEEE Standards Interpretations for IEEE Std 1003.2™-1992 IEEE Standard for Information Technology--Portable Operating System Interfaces (POSIX®)--Part 2: Shell and Utilities

Copyright © 1996 by the Institute of Electrical and Electronics Engineers, Inc. 3 Park Avenue New York, New York 10016-5997 USA All Rights Reserved.

Interpretations are issued to explain and clarify the intent of a standard and do not constitute an alteration to the original standard. In addition, interpretations are not intended to supply consulting information. Permission is hereby granted to download and print one copy of this document. Individuals seeking permission to reproduce and/or distribute this document in its entirety or portions of this document must contact the IEEE Standards Department for the appropriate license. Use of the information contained in this document is at your own risk.

IEEE Standards Department, Copyrights and Permissions, 445 Hoes Lane, Piscataway, New Jersey 08855-1331, USA

Interpretation Request #20
Topic: sh Relevant Sections:, 4.56.4

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 IEEE Std 1003.2- 1992 (July 1992), p. 21, lines 450-451] 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 126. [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 characters: - The implementation shall attempt to read that ffile 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.

Interpretation Response
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 permission. IEEE Std 1003.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 permissions. 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