WHICH(1) | User Commands | WHICH(1) |
which
— locate a
program file in the user's path
which |
[-as ] command ... |
The which
utility takes a list of command
names and searches the path for each executable file that would be run had
these commands actually been invoked.
Some shells may provide a built-in which
command which is similar or identical to this utility.
The following options are available:
The following operands are supported:
See environ(7) for
descriptions of the following environment variables that affect the
execution of which
:
PATH
.
The following exit values are returned:
Example 1 Locate the ‘ls’ and ‘cp’ commands.
$ /usr/bin/which ls cp /usr/bin/ls /usr/bin/cp
Example 2 Use a specific
PATH
and show all occurrences.
$ PATH=/usr/bin:/usr/has/bin /usr/bin/which -a edit /usr/bin/edit /usr/has/bin/edit
Example 3 Executable reported multiple times.
If PATH
contains repeated components, the
same executable can be reported more than once:
$ PATH=/usr/bin:/usr/bin /usr/bin/which -a ls /usr/bin/ls /usr/bin/ls
Example 4 Do not show output.
Just exit with an appropriate return code:
$ /usr/bin/which -s ls cp $ echo $? 0 $ /usr/bin/which -s fakecommand $ echo $? 1
The command line interface of which
is
Committed. The output of which
is
Committed.
March 15, 2023 | OmniOS |