summaryrefslogtreecommitdiff
path: root/which.texinfo
blob: 8e3a2e7fb7eeb70960fa3ba05c7a0620ebd07b76 (plain)
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
\input texinfo   @c -*-texinfo-*-
@c %**start of header
@setfilename which.info
@settitle @command{which}: show full path of commands
@include version.texi
@c %**end of header

@setchapternewpage odd

@ifinfo
@format

@c !BEGIN INTRO
This file documents `which' version 2.x@.
@c !END INTRO

@c !BEGIN COPYING
Copyright @copyright{} 2000, by

Carlo Wood, Run on IRC <carlo@@alinoe.com>
RSA-1024 0x624ACAD5 1997-01-26                    Sign & Encrypt
Fingerprint16 = 32 EC A7 B6 AC DB 65 A6  F6 F6 55 DD 1C DC FF 61

Permission is granted to make and distribute verbatim copies of
this manual provided the copyright notice and this permission notice
are preserved on all copies.
@end format

@ignore
Permission is granted to copy and distribute modified versions of this
manual under the conditions for verbatim copying, provided also that the
section entitled ``GNU General Public License'' is included exactly as
in the original, and provided that the entire resulting derived work is
distributed under the terms of a permission notice identical to this
one.

Permission is granted to copy and distribute translations of this manual
into another language, under the above conditions for modified versions,
except that the section entitled ``GNU General Public License'' may be
included in a translation approved by the author instead of in the
original English.
@end ignore
@c !END COPYING
@end ifinfo

@titlepage
@title Which
@subtitle Show the full path of commands
@sp 1
@subtitle Edition @value{EDITION}, for Which Version @value{VERSION}
@subtitle @value{UPDATED}
@c !BEGIN AUTHORS
@author Carlo Wood <@email{carlo@@gnu.org}>
@c !END AUTHORS
@page
@vskip 0pt plus 1filll
Copyright @copyright{} 2000, by

Carlo Wood, Run on IRC <carlo@@alinoe.com>
RSA-1024 0x624ACAD5 1997-01-26                    Sign & Encrypt
Fingerprint16 = 32 EC A7 B6 AC DB 65 A6  F6 F6 55 DD 1C DC FF 61

@end titlepage

@ifinfo
@node Top, Which Program, (dir), (dir)
@top @command{which}: Show the full path of commands

The @command{which} program
@c !BEGIN NAME
shows the full path of (shell) commands.
@c !END NAME

@noindent
This file documents @command{which} version @value{VERSION}, updated @value{UPDATED}.
@end ifinfo

@menu
* Which Program::               The @command{which} Program
* Invoking Which::              How to invoke @command{which}
* Option Summary::              Overview of commandline options
* Return Value::		The return value of @command{which}
* Example::			Examples of invokation
* Bugs::			Known bugs
* See Also::			Related UNIX commands
* Index::                       Index
@end menu

@node Which Program, Invoking Which, Top, Top
@chapter The @command{which} Program
@cindex Description of @command{which}

@c !BEGIN DESCRIPTION
@command{Which} 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 @env{PATH} using the same algorithm as @command{bash(1)}.
@c !END DESCRIPTION

@node    Invoking Which, Option Summary, Which Program, Top
@chapter Invoking @command{which}
@cindex Invoking @command{which}
@cindex Synopsis

@noindent
The synopsis to invoke @command{which} is

@c !BEGIN SYNOPSIS
@example
which [options] [--] programname [...]
@end example
@c !END SYNOPSIS

@menu
* Option Summary::        Option summary
@end menu

@node    Option Summary, Return Value, Invoking Which, Top
@chapter Option Summary
@cindex Options, command line
@cindex Command line Options
@cindex Overview of command line options

@c !BEGIN OPTIONS
@table @samp
@cindex @option{--all}
@cindex @option{-a}
@item --all
@itemx -a
Print all matching executables in @env{PATH}, not just the first.

@cindex @option{--read-alias}
@cindex @option{-i}
@item --read-alias
@itemx -i
Read aliases from stdin, reporting matching ones on
stdout. This is useful in combination with using an
alias for which itself. For example@*
@code{alias which='alias | which -i'}.

@cindex @option{--skip-alias}
@item --skip-alias
Ignore option @option{--read-alias}, if any. This is useful to
explicity search for normal binaries, while using
the @option{--read-alias} option in an alias or function for which.

@cindex @option{--read-functions}
@item --read-functions
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:@*
@code{which() @{ declare -f | which --read-functions $@@ @}@*export -f which}

@cindex @option{--skip-functions}
@item --skip-functions
Ignore option @option{--read-functions}, if any. This is useful to
explicity search for normal binaries, while using
the @option{--read-functions} option in an alias or function for which.

@cindex @option{--skip-dot}
@item --skip-dot
Skip directories in @env{PATH} that start with a dot.

@cindex @option{--skip-tilde}
@item --skip-tilde
Skip directories in @env{PATH} that start with a tilde and
executables which reside in the @env{HOME} directory.

@cindex @option{--show-dot}
@item --show-dot
If a directory in @env{PATH} starts with a dot and a matching
executable was found for that path, then print
"./programname" rather than the full path.

@cindex @option{--show-tilde}
@item --show-tilde
Output a tilde when a directory matches the @env{HOME}
directory. This option is ignored when which is
invoked as root.

@cindex @option{--tty-only}
@item --tty-only
Stop processing options on the right if not on tty.

@cindex @option{--version}
@cindex @option{-v}
@cindex @option{-V}
@item --version, -v, -V
Print version information on standard output then exit
successfully.

@cindex @option{--help}
@item --help
Print usage information on standard output then exit
successfully.

@end table
@c !END OPTIONS

@node    Return Value, Example, Option Summary, Top
@chapter Return Value
@cindex Return value of @command{which}

@c !BEGIN RETURNVALUE
@command{Which} returns the number of failed arguments, or -1 when
no @file{programname} was given.
@c !END RETURNVALUE

@node    Example, Bugs, Return Value, Top
@chapter Example
@cindex Examples
@cindex aliases, handling of

@c !BEGIN EXAMPLE
The recommended way to use this utility is by adding an alias (C shell)
or shell function (Bourne shell) for @command{which} like the following:

[ba]sh:

@example
@group
which ()
@{
  (alias; declare -f) | /usr/bin/which --tty-only --read-alias --read-functions --show-tilde --show-dot $@@
@}
export -f which
@end group
@end example

[t]csh:

@example
@group
alias which 'alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
@end group
@end example

@noindent
This will print the readable ~/ and ./ when starting which
from your prompt, while still printing the full path when
used from a script:

@example
@group
> which q2
~/bin/q2
> echo `which q2`
/home/carlo/bin/q2
@end group
@end example
@c !END EXAMPLE

@node    Bugs, See Also, Example, Top
@chapter Bugs
@cindex Bugs, known

@c !BEGIN BUGS
The @env{HOME} directory is determined by looking for the @env{HOME}
environment variable, which aborts when this variable
doesn't exist.  @command{Which} will consider two equivalent directories
to be different when one of them contains a path
with a symbolic link.
@c !END BUGS

@node    See Also, Index, Bugs, Top
@chapter See Also

@c !BEGIN SEEALSO
@command{bash(1)}
@c !END SEEALSO

@node    Index,            ,  See Also, Top
@comment node-name,    next,  previous,       up
@unnumbered Index

@printindex cp

@contents
@bye