Re: [PATCH v2] exec: Print absolute paths for command location queries
"Kerin Millar" <[email protected]> Sat, 13 Jun 2026 09:35:51 +0100
| Newsgroups | org.kernel.vger.dash |
|---|---|
| Message-ID | <[email protected]> |
On Sat, 13 Jun 2026, at 2:52 AM, Harald van Dijk wrote: > On 6/13/26 02:47, Herbert Xu wrote: >> Kerin Millar <[email protected]> wrote: >>> POSIX requires that, when reporting the location of a utility found by >>> searching PATH (or one named with a slash), the pathname written by >>> type, command -v and command -V be absolute: >>> >>> Executable utilities, regular built-in utilities, command_names >>> including a <slash> character, and any implementation-provided >>> functions that are found using the PATH variable [...] shall be >>> written as absolute pathnames. >>> >>> Presently, dash fails to conform in this regard. Address this issue by >>> prefixing relative pathnames with the logical current working directory, >>> provided that it still resolves to the current directory, and with the >>> physical current working directory otherwise. If the current working >>> directory cannot be determined, print the relative pathname instead. >>> >>> Link: https://lore.kernel.org/dash/[email protected]/ >>> Reported-by: Christoph Anton Mitterer <[email protected]> >>> Suggested-by: Harald van Dijk <[email protected]> >>> Signed-off-by: Kerin Millar <[email protected]> >>> --- >>> src/cd.c | 40 ++++++++++++++++++++++++++++++++++++---- >>> src/cd.h | 1 + >>> src/exec.c | 30 ++++++++++++++++++++++++++---- >>> 3 files changed, 63 insertions(+), 8 deletions(-) >> >> Even bash doesn't do this: >> >> $ bash -o posix -c 'cd /; command -v bin/bash' >> bin/bash >> $ > > You're overlooking the "that are found using the PATH variable" from the > spec. Because you included a / in the command, it is not looked up from > PATH. Modifying your test to make sure PATH is used, we can see that > bash does do this in POSIX mode: > > $ bash -c 'cd /; PATH=bin command -v bash' > bin/bash > $ bash -o posix -c 'cd /; PATH=bin command -v bash' > /bin/bash Adjacently, bash willfully supports / in function names. $ bash -c 'bin/bash() { echo 1; }; bin/bash' 1 $ bash --posix -c 'bin/bash() { echo 1; }; bin/bash' bash: line 1: bin/bash: No such file or directory -- Kerin Millar