1

If I type command on my terminal, I don't get "command not found", and the exit code is 0. I assume that this means command actually does something on bash.

Also, command -h returns:

bash: command: -h: invalid option
command: usage: command [-pVv] command [arg ...]

What is it used for?

  • 1
    Have a look at the man page for command. It describes exactly what it does. – n8te Oct 29 '16 at 1:11
  • 1
    @n8te: You should instead give a quick summary of what it does as an answer, also refering to the man page. – Julie Pelletier Oct 29 '16 at 1:23
5

From help command:

$ 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.

As a more general note, rather than just using -h when you don't know what a command does, you should try:

type -a command

Which would in this case have told you it is a shell builtin.

help command

is good for shell builtins. For other commands (and also for shell builtins, actually), try

man somecommand

Also, -h is not necessarily the "help" option. If you don't know what a command does, that may not be a safe assumption to make. Safer is --help.

somecommand --help

(Common commands where -h is a valid option but does not mean "help" are ls, free, df, du. All of these are informational only, but the assumption that -h will only ever mean "help" is a dangerous assumption.)

  • 1
    Thanks for the extra advice on -h. I have been using bash for a while, but I still make these kinds of mistakes often. – Alberto Rivera Oct 29 '16 at 1:32
  • 2
    Although the help doesn't say so, command xyz also implicitly suppresses an alias xyz because xyz is no longer the first token. – dave_thompson_085 Oct 29 '16 at 7:07
  • @Wildcard could you explain what is the "shell function lookup" mentioned in the manual? – Sergio Aug 25 '18 at 8:00
0

command like almost everything else Unix/Linux is documented in man pages. Typing man command provides the manual for bash which has a subsection devoted to the built-in command command:

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 the -p option is given, the search for command is performed using a default value for PATH that is guaranteed to find all of the standard utilities. If either the -V or -v option is supplied, a description of command is printed. The -v option causes a single word indicating the command or filename used to invoke command to be displayed; the -V option produces a more verbose description. 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.