View Issue Details

IDProjectCategoryView StatusLast Update
00020021003.1(2024)/Issue8System Interfacespublic2026-11-02 16:30
Reporterstephane Assigned To 
PrioritynormalSeverityObjectionTypeEnhancement Request
Status NewResolutionOpen 
NameStephane Chazelas
Organization
User Reference
Sectionhttps://pubs.opengroup.org/onlinepubs/9799919799/functions/execl.html
Page Numberhttps://pubs.opengroup.org/onlinepubs/9799919799/functions/execl.html
Line Numberhttps://pubs.opengroup.org/onlinepubs/9799919799/functions/execl.html
Interp Status
Final Accepted Text
Summary0002002: execlp() / execvp() and commands starting with - or +
DescriptionSimilar to 0001440, related to 0001600

https://pubs.opengroup.org/onlinepubs/9799919799.2024edition/functions/execl.html has:

"""
In the cases where the other members of the exec family of functions would fail and set errno to [ENOEXEC], the execlp() and execvp() functions shall execute a command interpreter and the environment of the executed command shall be as if the process invoked the sh utility using execl() as follows:

execl(<shell path>, <name>, file, <args>, (char *)0);


where <shell path> is an unspecified pathname for the sh utility, <name> is an unspecified string, file is the process image file, and where <args> is zero or more parameters corresponding to any initial non-null arguments passed after arg0 for execlp() or to any initial non-null members of argv starting at argv[1] for execvp().
"""

"file is the process image file" should probably be "file is the pathname to the process image file", but also, if that pathname starts with - or +, such as when invoked as execlp("-dir-/cmd",...) or execlp("+x",...) and +x was found in the current directory because $PATH contains an empty component, then that path will be taken as an option by sh instead of the path to the file being executed.

There's a similar problem in the resolution of 0001600 where

#! /path/to/sh
${0##*/} "$@"


Should be:

#! /path/to/sh --
"${0##*/}" "$@"


(leaving that ${0##*/} unquoted to request split+glob also doesn't make sense here)

Desired ActionFor execlp/execvp, change to:

"""
execl(<shell path>, <name>, "--", file, <args>, (char *)0);


where <shell path> is an unspecified pathname for the sh utility, <name> is an unspecified string, file is the pathname of the process image file, and where <args> is zero or more parameters corresponding to any initial non-null arguments passed after arg0 for execlp() or to any initial non-null members of argv starting at argv[1] for execvp().
"""

Apparently Solaris/Illumos prefix the path with ./ if it starts with - (not +) instead (https://github.com/illumos/illumos-gate/blob/7bbcc14f12e8a235cc9668f76da6d2c9ecf14cd4/usr/src/lib/libc/port/gen/execvp.c#L156-L158). We may want to also allow that even if that means that changes the value of `$0` in the shell script.

For the builtins (0001600 resolution):

#! /path/to/sh --
"${0##*/}" "$@"


Using a single dash as in:

#! /path/to/sh -
"${0##*/}" "$@"


May be more canonical as that's what was done for the Bourne shell.
TagsNo tags attached.

Relationships

related to 0001600 Closed 1003.1(2016/18)/Issue7+TC2 Problems with the suggested single-line shell script: $0 "$@" 

Activities

There are no notes attached to this issue.

Issue History

Date Modified Username Field Change
2026-10-28 18:50 stephane New Issue
2026-11-02 16:30 msbrown Relationship added related to 0001600