Last Updated: February 25, 2016
· sheerun
Photo on 08.01.2013 at 04.15

Get command path in POSIX shell

command -v <command>

For example:

$ command -v find

As POSIX.1-2008 documentation says command -v:

Write a string to standard output that indicates the pathname or command that will be used by the shell, in the current shell execution environment (see Shell Execution Environment), to invoke commandname, but do not invoke commandname.

Utilities, regular built-in utilities, command_names including a <slash> character, and any implementation-defined functions that are found using the PATH variable (as described in Command Search and Execution), shall be written as absolute pathnames.

Shell functions, special built-in utilities, regular built-in utilities not associated with a PATH search, and shell reserved words shall be written as just their names.

An alias shall be written as a command line that represents its alias definition.

Otherwise, no output shall be written and the exit status shall reflect that the name was not found.

WARNING: this won't work for shell aliases. For shell functions only name of function is printed.