Re: [PATCH v2] exec: Print absolute paths for command location queries

Herbert Xu <[email protected]> Sat, 13 Jun 2026 09:47:51 +0800
Newsgroups org.kernel.vger.dash
Message-ID <[email protected]>
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
$ 

Thanks,
-- 
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt