[Toybox] command -v vs type

Rob Landley rob at landley.net
Thu Aug 6 18:52:56 UTC 2026


On 8/5/26 16:48, Chet Ramey via Toybox wrote:
> On 8/5/26 4:44 PM, Rob Landley wrote:
> 
>> I am learning all SORTS of new things. And then going "so do type -p 
>> and or type -P have the same behavior as exec" and I'm still trying to 
>> wrap my head around...

I started by implementing what the help text said, which didn't _not_ 
say that -p and -P were identical. In reality, -P always shows a path 
search result if there is one, and -p shows nothing (but returns 
success) if something OTHER than a path search has priority.

So if there's a "sub/if" in the $PATH -P will show it and -p won't. (And 
thus a test for -pf can show a behavior variance -Pf shouldn't...) Which 
I only discovered from testing, not from documentation.

>> $ mkdir sub; touch sub/walrus # but NOT chmod +x
>> $ PATH=sub:$PATH type -P walrus
>> sub/walrus
> 
> That's the file that will be `executed' if you type `walrus' and go through
> a $PATH search.

Modulo the exec bit behavior variance...

>> $ PATH=sub:$PATH type -a walrus
>> bash: type: walrus: not found
> 
> Yep, -a has always been this way (finding executable files only). I don't
> think it's particularly consistent, but I'm not changing it now.

And I need to match the behavior, I was just trying to figure out if 
there was a pattern I wasn't seeing.

>> And I need ALL those tests because each one of those behaviors is 
>> inconsistent with other parts of command/type.
> 
> Don't think of `command' and `type' as identical. `type' existed long
> before POSIX even thought of `command -v' and `command -V'.

I don't think they're identical but they do share infrastructure and 
thus I implemented them at the same time.

And it's not just type vs command vs actual path search to run stuff: 
with "type -pP" the capital version always wins, but with "type -tp" the 
last one listed wins. It's inconsistent within the same command...

> If I could
> change anything, I would change `command's behavior when given multiple
> command-name arguments to match `type's, but that ship sailed a long
> time ago.
Yup. I'm not asking you to change behavior (makes it harder for me if 
you do).

I was just hoping there was a rule that would collapse stuff together 
that I wasn't seeing. (Or would suggest test cases I hadn't thought of.)

Thanks,

Rob


More information about the Toybox mailing list