Re: `command -p` Not Searching Path

Harald van Dijk <[email protected]>
Newsgroups org.kernel.vger.dash
Message-ID <[email protected]>
On 11/08/2026 12:38, Martijn Dekker wrote:
> Op 09-08-2026 om 20:49 schreef Nathan Royce:
>> 5) $ command -p echo //SHOULD have been from PATH, which we made to
>> be a copy of `ls`
> 
> 
> The '-p' only changes one thing about the behaviour of 'command': it 
> causes the system's default path list (as shown by 'getconf PATH') to be 
> used instead of $PATH while doing a path search. The purpose is to 
> ignore the user's $PATH setting in cases where it shouldn't be trusted. 
> In other words, the option guarantees the use of known-good standard 
> utilities.
> 
> The option changes nothing else, so this still only disables the lookup 
> of aliases and functions -- not builtins, which continue to take 
> precedence over external commands. It's not possible to change this 
> without breaking compatibility.

This is all correct but it is worth pointing out this is an intentional 
deviation from POSIX in (almost?) every shell. POSIX specifies that 
builtins should be associated with a specific directory, so that PATH 
can override builtins.

In dash, if any entry in PATH is %builtin, builtins are checked at that 
point in command lookup and earlier entries can override builtins. With 
dash 0.5.12, where echo is implemented as a builtin which does not 
support \x, but /bin/echo does support \x:

$ src/dash -c 'echo "\x40"; PATH=$PATH:%builtin; echo "\x40"'
@
\x40

Cheers,
Harald van Dijk
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.