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