[Toybox] command -v vs type
Chet Ramey
chet.ramey at case.edu
Wed Aug 5 21:48:02 UTC 2026
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...
>
> $ 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.
> $ 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.
> $ PATH=sub:$PATH type -Pa walrus
> $ echo $?
> 1
Yep, the -a forces a search for executable files only. The only thing -P
does is force the $PATH search.
> $ touch sub/xx; chmod +x sub/xx
> $ PATH=sub:$PATH type -Pa xx walrus
> sub/xx
> $ echo $?
> 1
Yep, if any of the names is not found, `type' returns 1.
> 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'. 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.
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU chet at case.edu http://tiswww.cwru.edu/~chet/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature.asc
Type: application/pgp-signature
Size: 203 bytes
Desc: OpenPGP digital signature
URL: <http://lists.landley.net/pipermail/toybox/attachments/20260805/e79bac6e/attachment-0001.sig>
More information about the Toybox
mailing list