Base WG Resolution Ref: bwg2000-004
Topic: #! executable scripts

This is an approved Base Working Group Resolution for XCU5.

Last update: 29 April,2000

								2000 #004


	Topic:			#! executable scripts
	Relevant Sections:	shell command language
	Spec:			XCU5

Resolution Request:

XCU does not include the common #! script handling syntax.
This is widely used in the industry.

Proposed resolution:

Add the following as an XSI extension in a future revision (line
numbers are given against the Austin Group D3):

* Add the following definition to XBD:

Executable Script:

An executable file of which the first two characters are "#!"
as defined in the portable character set.

Some systems only recognize an executable script when it
starts with the four bytes `#! /'.

See the Shell Command Language Introduction Section 2.1 on page XX.

* Change sentence 2 of Bullet 1 of section 2.1 on XCU D3 page 35 to:

"If the first line of a file of shell commands starts with the
characters "#!", and if the system is XSI-conformant it shall behave as
described in Executable Script on page XX, otherwise the results are

* Fixup Rationale on page 35 of XCU

Change the paragraph beginning on l 1225:
"The construct "#!" is reserved for implementations..." to

"The construct "#!" is reserved for POSIX implementations..." 

Change line 1227
"conforming application" to "conforming POSIX application"

Add a new sentence at line 1228:

"The construct #! is defined for XSI-conformant systems and
XSI-conforming applications."

* Add new part into the Shell Command Language description
(will need to find a suitable location)

[XSI shade on]

Executable Script

XSI-Conformant systems shall support executable scripts. A successful
call to a function of the exec family with an executable script as
the first parameter shall result in a new process, where the process
image that is started is that of the interpreter. The path name of
the interpreter follows the "#!" characters .  

If the executable script has a first line

        #! interpreter [arg]

then the interpreter shall be called with an argument array
consisting of an unspecified zeroth argument, followed
by arg (if present), followed by a path name for the
script, followed by the arguments following the zeroth argument
in the exec call of the script. 

No shell operations (as described above in section 2.1) shall 
be performed on the first line of an executable script.

The first line of the executable script shall meet all of the following
criteria otherwise the results are unspecified:
1.  Is of one of the forms:
	"#!%s\n" interpreter
	"#!d%s\n" interpreter
	"#!%sd%s\n" interpreter arg
	"#!d%sd%s\n" interpreter arg
    [Note: "d" in all places in the above formats is replaced by the
    delta character than indicates exactly one <space> character rather
    than the arbitrary number of <space> and <tab> characters indicated
    by using a space in a format string.]

2.  The interpreter argument is an absolute pathname of an executable
    file other than an executable script.

3.  Neither the interpreter argument nor the arg argument, if present,
    contain any quoting characters.

4.  Neither the interpreter argument nor the arg argument, if present,
    contain any whitespace characters.

5.  The length of the entire line is no longer than 80 bytes.  
    XSI-conforming applications shall not specifiy
    a first line length of more than 80 characters.


The working group did not reach consensus to adopt this as a core
requirement, however existing practise on UNIX systems indicated that
it should be added as an XSI extension.

Applications must not assume that the standard utilities will
be available in any  particular named directory. For example it cannot be
assumed that standard versions of awk and sh will be available 
as "/bin/sh" or "/bin/awk" respectively, since implementations are 
permitted to provide non standard versions of the utilities in these 

It is recommended that an installation script for 
executable scripts, use the standard PATH returned by a call to the 
getconf utility with the argument PATH, combined with the command
utility to determine the location of a standard utility:

For example to determine the location of the standard sh utility:
	PATH=`getconf PATH` command -v sh

On some systems this might return

Note that the installation script should ensure that the returned
pathname is an absolute pathname prior to use, since a shell builtin 
might be returned for some utilities.

in XCUd3 page 900 sh APPLICATION USAGE

Change the example from 

#! /bin/sh - 


#! /usr/bin/sh -

and add a note "The standard PATH to the shell cannot be
assumed to be either "/bin/sh" or "/usr/bin/sh" and should be determined
by interrogation of the PATH returned by getconf PATH, ensuring
that the  returned pathname is an absolute pathname and not a shell builtin ."

For example to determine the location of the standard sh utility:
	PATH=`getconf PATH` command -v sh

On some systems this might return

Resolution Response

A future revision of the specification will include the
proposed changes.


Circulated for review: 26 Apr 2000
Proposed resolution: 27 Apr 2000
Approved: April 2000