#292751 bash man page does not mention that "command -v" prints names of builtins and functions too

Package:
bash
Source:
bash
Description:
GNU Bourne Again SHell
Submitter:
Thomas Hood
Date:
2024-04-15 12:27:04 UTC
Severity:
normal
Tags:
#292751#5
Date:
2005-01-29 14:00:35 UTC
From:
To:
The following log shows that "command -v" prints the name of a shell
function even though the man page says that shell functions are
supposed to be excluded from the search.

$ foo() { echo fjdskfjs ; }
$ foo
fjdskfjs
$ command -v foo
foo
$ echo $?
0
$ command foo
bash: foo: command not found
$ echo $?
127

       command [-pVv] command [arg ...]
              Run command with args suppressing the normal
              shell function lookup. Only builtin commands
              or  commands found in the PATH are executed.
              [...]                    If either the -V or
              -v option is supplied, a description of com-
              mand  is  printed.   The  -v option causes a
              single word indicating the command  or  file
              name used to invoke command to be displayed;
              [...]         If the -V or -v option is sup-
              plied, the exit status is 0 if  command  was
              found,  and  1 if not.  If neither option is
              supplied and an error  occurred  or  command
              cannot  be  found,  the  exit status is 127.
              Otherwise, the exit status  of  the  command
              builtin is the exit status of command.

#292751#18
Date:
2005-09-10 15:36:30 UTC
From:
To:
Matthias Klose wrote:

The man page does not say that, though it's not obvious.  Rather than
specify two different builtins, POSIX chose to standardize `command'
with two essentially independent modes.  When used to run a command, it
skips shell function lookup.  When invoked with `-v' or `-V', it behaves
like `type', and shell functions are included.  If you look at the POSIX
description of `-v' and `-V', you'll see that shell functions are
explicitly included.

Chet