Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 2

up vote 6 down vote accepted

This is built-in command of the Bash shell.

The only advantage I see with this built-in is summarized in the following sentence of the help text :

Can be used to invoke commands on disk when a function with the same name exists

So if you want to execute a program (a binary file saved of some of your disk), and an internal shell function of the same name exist, then you can invoke your program using this built-in.

And yes, command -v will give the same kind of result as type.

I've found it also under the Dash shell.

share|improve this answer
    
What's worth adding more explicitly is that although command (name) ignoes shell functions, command -v (name) does not. command -v (name) >/dev/null is supposed to be the portable way of checking whether the command with that name exists, regardless of whether it's a shell builtin, function, or external utility. –  hvd Aug 18 at 11:49
    
command -v is the posix alternative to which, type, etc, stackoverflow.com/questions/762631/… –  chilicuil Aug 18 at 13:23

According to the help section you posted yourself, it just tells you how commands work in general. I don't think there is a command called "command".

Executing "command" in a terminal gives no results or feedback.

share|improve this answer
3  
You think wrong. Run type command to check out that command is a shell builtin command. –  Radu Rădeanu Aug 18 at 9:01

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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