[Toybox] command -v vs type

Rob Landley rob at landley.net
Tue Aug 4 18:50:18 UTC 2026


On 8/3/26 11:42, Chet Ramey wrote:
> On 8/1/26 11:56 PM, Rob Landley wrote:
>> $ command -v nothing cat; echo $?
>> /bin/cat
>> 0
>> $ type nothing cat; echo $?
>> bash: type: nothing: not found
>> cat is /bin/cat
>> 1
>> $ help command | grep -w '[-]v'
>>        -v    print a description of COMMAND similar to the `type' builtin
>>
>> Why?
> 
> More or less a Posix-vs-history thing. `type' is not standardized; bash
> inherited it from the System V sh, so it makes sense to keep the same
> behavior.
> 
> For `command', there is ... disagreement. Posix only standardizes the
> behavior with a single argument; everyone agrees on that behavior. If
> there are multiple arguments, all bets are off, and bash chose `find
> any' to succeed, figuring it was closest to what Posix would have
> specified. This is a decision made in the mid-1990s.

I was confused by command and type behaving _different_ when the help 
just says that -v is similar to "type". (The man page also says "If the 
-V or -v option  is supplied, the  exit  status  is  0 if command was 
found, and 1 if not." which is not much more informative.)

command: command [-pVv] command [arg ...]
     Execute a simple command or display information about commands.
...
     Exit Status:
     Returns exit status of COMMAND, or failure if COMMAND is not found.

I thought maybe that meant the FIRST one listed was controlling the exit 
status, hence the "nothing cat" ordering above. But honestly, there are 
just SO many little weird...

$ mkdir sub sub2
$ tee echo hello sub/hello > sub2/hello
$ chmod +x sub2/hello
$ PATH=sub:sub2:$PATH hello
hello
$ rm sub2/hello
$ PATH=sub:sub2:$PATH hello
bash: sub/hello: Permission denied

It continues past non-executable commands to find an executable one in 
the $PATH, but if there _isn't_ an executable one it REMEMBERS the 
non-executable one for the error message. (It does not, as far as I can 
tell, try to EXEC more than one...)

Then there's:

$ PATH=sub:$PATH
$ type sub/xx
sub/xx is sub/xx
$ type xx
xx is sub/xx
$ command -V sub/xx
sub/xx is sub/xx
$ command -V xx
xx is /home/landley/toybox/toybox/sub/xx

Why does that one uniquely expand to absolute path? (Not a _cannonical_ 
path, if sub is a symlink it's still there...)

(Yeah I know, it goes in the "builtin 'echo --help' doesn't but 
'/bin/echo --help' does bucket. It just is. But I have SO MANY TEST 
CASES...)

> Chet

Rob


More information about the Toybox mailing list