Re: [PATCH v2] exec: Print absolute paths for command location queries
Harald van Dijk <[email protected]> Sat, 13 Jun 2026 02:52:29 +0100
| Newsgroups | org.kernel.vger.dash |
|---|---|
| Message-ID | <[email protected]> |
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 Cheers, Harald van Dijk