About
This article talks about the builtin command utility command. To know what a command means in the context of bash, see What is a Command in Bash?
The command function suppress the the shell function lookup in the search command order.
For command as a bash definition, see What is a Command in Bash?.
Articles Related
Syntax
command [-pVv] command [arg ...]
where:
- args are arguments
- p will guarantee to find all of the standard utilities by using a default value for PATH.
- v causes a single word indicating the command or file name used to invoke command to be displayed;
- V produces a more verbose description.
If either the V or v option is supplied, a description of command is printed.
Exit Status
- If the -V or -v option is supplied, 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.
Snippet
have_command () {
command -v "$1" >/dev/null 2>/dev/null
}
require_command () {
if ! have_command "$1"; then
die 1 "Could not find required command '$1' in system PATH. Aborting."
fi
}