| 1 |
.TH WHICH 1 |
| 2 |
.rn RS Rs |
| 3 |
.de RS |
| 4 |
.na |
| 5 |
.nf |
| 6 |
.Rs |
| 7 |
.. |
| 8 |
.rn RE Re |
| 9 |
.de RE |
| 10 |
.Re |
| 11 |
.fi |
| 12 |
.ad |
| 13 |
.. |
| 14 |
.de Sx |
| 15 |
.PP |
| 16 |
.ne \\$1 |
| 17 |
.RS |
| 18 |
.. |
| 19 |
.de Ex |
| 20 |
.RE |
| 21 |
.PP |
| 22 |
.. |
| 23 |
.na |
| 24 |
.SH NAME |
| 25 |
which \- shows the full path of (shell) commands. |
| 26 |
.SH SYNOPSIS |
| 27 |
.B which |
| 28 |
[options] [\-\-] programname [...] |
| 29 |
.SH DESCRIPTION |
| 30 |
\fBWhich\fR takes one or more arguments. For each of its arguments |
| 31 |
it prints to stdout the full path of the executables |
| 32 |
that would have been executed when this argument had been |
| 33 |
entered at the shell prompt. It does this by searching |
| 34 |
for an executable or script in the directories listed in |
| 35 |
the environment variable \fBPATH\fR using the same algorithm as \fBbash(1)\fR. |
| 36 |
|
| 37 |
This man page is generated from the file \fIwhich.texinfo\fR. |
| 38 |
.SH OPTIONS |
| 39 |
|
| 40 |
.TP 4 |
| 41 |
.B --all\fR, \fB-a\fR |
| 42 |
Print all matching executables in \fBPATH\fR, not just the first. |
| 43 |
.TP |
| 44 |
.B --read-alias\fR, \fB-i\fR |
| 45 |
Read aliases from stdin, reporting matching ones on |
| 46 |
stdout. This is useful in combination with using an |
| 47 |
alias for which itself. For example |
| 48 |
.br |
| 49 |
.B |
| 50 |
alias which=\'alias | which -i\'\fR. |
| 51 |
.TP |
| 52 |
.B --skip-alias\fR |
| 53 |
Ignore option \`--read-alias\', if any. This is useful to |
| 54 |
explicity search for normal binaries, while using |
| 55 |
the \`--read-alias\' option in an alias or function for which. |
| 56 |
.TP |
| 57 |
.B --read-functions\fR |
| 58 |
Read shell function definitions from stdin, reporting matching |
| 59 |
ones on stdout. This is useful in combination with using a shell |
| 60 |
function for which itself. For example: |
| 61 |
.br |
| 62 |
.B |
| 63 |
which() { declare -f | which --read-functions $@ } |
| 64 |
.br |
| 65 |
export -f which\fR |
| 66 |
.TP |
| 67 |
.B --skip-functions\fR |
| 68 |
Ignore option \`--read-functions\', if any. This is useful to |
| 69 |
explicity search for normal binaries, while using |
| 70 |
the \`--read-functions\' option in an alias or function for which. |
| 71 |
.TP |
| 72 |
.B --skip-dot\fR |
| 73 |
Skip directories in \fBPATH\fR that start with a dot. |
| 74 |
.TP |
| 75 |
.B --skip-tilde\fR |
| 76 |
Skip directories in \fBPATH\fR that start with a tilde and |
| 77 |
executables which reside in the \fBHOME\fR directory. |
| 78 |
.TP |
| 79 |
.B --show-dot\fR |
| 80 |
If a directory in \fBPATH\fR starts with a dot and a matching |
| 81 |
executable was found for that path, then print |
| 82 |
"./programname" rather than the full path. |
| 83 |
.TP |
| 84 |
.B --show-tilde\fR |
| 85 |
Output a tilde when a directory matches the \fBHOME\fR |
| 86 |
directory. This option is ignored when which is |
| 87 |
invoked as root. |
| 88 |
.TP |
| 89 |
.B --tty-only\fR |
| 90 |
Stop processing options on the right if not on tty. |
| 91 |
.TP |
| 92 |
.B --version,-v,-V\fR |
| 93 |
Print version information on standard output then exit |
| 94 |
successfully. |
| 95 |
.TP |
| 96 |
.B --help\fR |
| 97 |
Print usage information on standard output then exit |
| 98 |
successfully. |
| 99 |
.SH RETURN VALUE |
| 100 |
\fBWhich\fR returns the number of failed arguments, or -1 when |
| 101 |
no \`programname\' was given. |
| 102 |
.SH EXAMPLE |
| 103 |
The recommended way to use this utility is by adding an alias (C shell) |
| 104 |
or shell function (Bourne shell) for \fBwhich\fR like the following: |
| 105 |
|
| 106 |
[ba]sh: |
| 107 |
|
| 108 |
.in +5 |
| 109 |
.nf |
| 110 |
.na |
| 111 |
which () |
| 112 |
{ |
| 113 |
(alias; declare -f) | /usr/bin/which --tty-only --read-alias --read-functions --show-tilde --show-dot $@ |
| 114 |
} |
| 115 |
export -f which |
| 116 |
.in -5 |
| 117 |
.ad |
| 118 |
.fi |
| 119 |
|
| 120 |
[t]csh: |
| 121 |
|
| 122 |
.in +5 |
| 123 |
.nf |
| 124 |
.na |
| 125 |
alias which \'alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde\' |
| 126 |
.in -5 |
| 127 |
.ad |
| 128 |
.fi |
| 129 |
|
| 130 |
This will print the readable ~/ and ./ when starting which |
| 131 |
from your prompt, while still printing the full path when |
| 132 |
used from a script: |
| 133 |
|
| 134 |
.in +5 |
| 135 |
.nf |
| 136 |
.na |
| 137 |
> which q2 |
| 138 |
~/bin/q2 |
| 139 |
> echo \`which q2\` |
| 140 |
/home/carlo/bin/q2 |
| 141 |
.in -5 |
| 142 |
.ad |
| 143 |
.fi |
| 144 |
|
| 145 |
.SH BUGS |
| 146 |
The \fBHOME\fR directory is determined by looking for the \fBHOME\fR |
| 147 |
environment variable, which aborts when this variable |
| 148 |
doesn\'t exist. \fBWhich\fR will consider two equivalent directories |
| 149 |
to be different when one of them contains a path |
| 150 |
with a symbolic link. |
| 151 |
.SH AUTHOR |
| 152 |
.br |
| 153 |
Carlo Wood <[email protected]> |
| 154 |
.SH "SEE ALSO" |
| 155 |
\fBbash(1)\fR |