Bash - Command (The Builtin command command)

About

This article talks about the builtin command utility command. To know what a command means in the context of bash, see Bash - (Simple) (Command | Expression)

The command function suppress the the shell function lookup in the search command order.

For command as a bash definition, see Bash - (Simple) (Command | Expression).

Syntax

command [-pVv] command [arg ...] 

where:

  • command is the command to execute. Only builtin commands or commands found in the PATH are executed.
  • 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
}

Documentation / Reference


Powered by ComboStrap