Recently I found command: command
which has no manual entry but help displays as follows:
$ help command
command: command [-pVv] command [arg ...]
Execute a simple command or display information about commands.
Runs COMMAND with ARGS suppressing shell function lookup, or display
information about the specified COMMANDs. Can be used to invoke commands
on disk when a function with the same name exists.
Options:
-p use a default value for PATH that is guaranteed to find all of
the standard utilities
-v print a description of COMMAND similar to the `type' builtin
-V print a more verbose description of each COMMAND
Exit Status:
Returns exit status of COMMAND, or failure if COMMAND is not found.
Is command -v
is alternative of which
?
What arguments are accepted by this command and how/when to use command
?
Best Answer
command
is a bash builtin as we can see:So we know
command
is provided by our shell, bash. Digging intoman bash
we can see what its use is:(from
man bash
):Essentially you would use
command
to bypass "normal function lookup". For example, say you had a function in your.bashrc
:Normally, when you run
say_hello
in your terminal bash would find the function namedsay_hello
in your.bashrc
before it found, say, an application namedsay_hello
. Using:makes bash bypass its normal function lookup and go straight to either builtins or your
$PATH
. Note that this function lookup also include aliases. Usingcommand
will bypass both functions and aliases.If the
-p
option is provided bash bypasses your custom$PATH
and uses its own default.The
-v
or-V
flags bash prints a description (short for-v
, long for-V
) of the command.Note: As souravc pointed out in the comments an easier method for finding information about shell builtins can be found here: How to make `man` work for shell builtin commands and keywords?