1 \input texinfo @c -*-texinfo-*-
3 @setfilename which.info
4 @settitle @command{which}: show full path of commands
6 @dircategory System administration
8 * Which: (which). Show full path of commands.
12 @setchapternewpage odd
18 This file documents `which' version 2.x@.
22 Copyright @copyright{} 2000 - 2015, by
24 Carlo Wood, Run on IRC <carlo@@alinoe.com>
25 RSA-1024 0x624ACAD5 1997-01-26 Sign & Encrypt
26 Fingerprint16 = 32 EC A7 B6 AC DB 65 A6 F6 F6 55 DD 1C DC FF 61
28 Permission is granted to make and distribute verbatim copies of
29 this manual provided the copyright notice and this permission notice
30 are preserved on all copies.
34 Permission is granted to copy and distribute modified versions of this
35 manual under the conditions for verbatim copying, provided also that the
36 section entitled ``GNU General Public License'' is included exactly as
37 in the original, and provided that the entire resulting derived work is
38 distributed under the terms of a permission notice identical to this
41 Permission is granted to copy and distribute translations of this manual
42 into another language, under the above conditions for modified versions,
43 except that the section entitled ``GNU General Public License'' may be
44 included in a translation approved by the author instead of in the
52 @subtitle Show the full path of commands
54 @subtitle Edition @value{EDITION}, for Which Version @value{VERSION}
55 @subtitle @value{UPDATED}
57 @author Carlo Wood <@email{carlo@@gnu.org}>
60 @vskip 0pt plus 1filll
61 Copyright @copyright{} 2000 - 2015, by
63 Carlo Wood, Run on IRC <carlo@@alinoe.com>
64 RSA-1024 0x624ACAD5 1997-01-26 Sign & Encrypt
65 Fingerprint16 = 32 EC A7 B6 AC DB 65 A6 F6 F6 55 DD 1C DC FF 61
70 @node Top, Which Program, (dir), (dir)
71 @top @command{which}: Show the full path of commands
75 The @command{which} program
77 shows the full path of (shell) commands.
81 This file documents @command{which} version @value{VERSION}, updated @value{UPDATED}.
85 * Which Program:: The @command{which} Program
86 * Invoking Which:: How to invoke @command{which}
87 * Option Summary:: Overview of commandline options
88 * Return Value:: The return value of @command{which}
89 * Example:: Examples of invokation
91 * See Also:: Related UNIX commands
95 @node Which Program, Invoking Which, Top, Top
96 @chapter The @command{which} Program
97 @cindex Description of @command{which}
100 @command{Which} takes one or more arguments. For each of its arguments
101 it prints to stdout the full path of the executables
102 that would have been executed when this argument had been
103 entered at the shell prompt. It does this by searching
104 for an executable or script in the directories listed in
105 the environment variable @env{PATH} using the same algorithm as @command{bash(1)}.
108 @node Invoking Which, Option Summary, Which Program, Top
109 @chapter Invoking @command{which}
110 @cindex Invoking @command{which}
114 The synopsis to invoke @command{which} is
118 which [options] [--] programname [...]
123 * Option Summary:: Option summary
126 @node Option Summary, Return Value, Invoking Which, Top
127 @chapter Option Summary
128 @cindex Options, command line
129 @cindex Command line Options
130 @cindex Overview of command line options
134 @cindex @option{--all}
138 Print all matching executables in @env{PATH}, not just the first.
140 @cindex @option{--read-alias}
144 Read aliases from stdin, reporting matching ones on
145 stdout. This is useful in combination with using an
146 alias for which itself. For example@*
147 @code{alias which='alias | which -i'}.
149 @cindex @option{--skip-alias}
151 Ignore option @option{--read-alias}, if any. This is useful to
152 explicity search for normal binaries, while using
153 the @option{--read-alias} option in an alias or function for which.
155 @cindex @option{--read-functions}
156 @item --read-functions
157 Read shell function definitions from stdin, reporting matching
158 ones on stdout. This is useful in combination with using a shell
159 function for which itself. For example:@*
160 @code{which() @{ declare -f | which --read-functions $@@ @}@*export -f which}
162 @cindex @option{--skip-functions}
163 @item --skip-functions
164 Ignore option @option{--read-functions}, if any. This is useful to
165 explicity search for normal binaries, while using
166 the @option{--read-functions} option in an alias or function for which.
168 @cindex @option{--skip-dot}
170 Skip directories in @env{PATH} that start with a dot.
172 @cindex @option{--skip-tilde}
174 Skip directories in @env{PATH} that start with a tilde and
175 executables which reside in the @env{HOME} directory.
177 @cindex @option{--show-dot}
179 If a directory in @env{PATH} starts with a dot and a matching
180 executable was found for that path, then print
181 "./programname" rather than the full path.
183 @cindex @option{--show-tilde}
185 Output a tilde when a directory matches the @env{HOME}
186 directory. This option is ignored when which is
189 @cindex @option{--tty-only}
191 Stop processing options on the right if not on tty.
193 @cindex @option{--version}
196 @item --version, -v, -V
197 Print version information on standard output then exit
200 @cindex @option{--help}
202 Print usage information on standard output then exit
208 @node Return Value, Example, Option Summary, Top
209 @chapter Return Value
210 @cindex Return value of @command{which}
212 @c !BEGIN RETURNVALUE
213 @command{Which} returns the number of failed arguments, or -1 when
214 no @file{programname} was given.
217 @node Example, Bugs, Return Value, Top
220 @cindex aliases, handling of
223 The recommended way to use this utility is by adding an alias (C shell)
224 or shell function (Bourne shell) for @command{which} like the following:
232 (alias; declare -f) | /usr/bin/which --tty-only --read-alias --read-functions --show-tilde --show-dot $@@
242 alias which 'alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
247 This will print the readable ~/ and ./ when starting which
248 from your prompt, while still printing the full path when
261 @node Bugs, See Also, Example, Top
266 The @env{HOME} directory is determined by looking for the @env{HOME}
267 environment variable, which aborts when this variable
268 doesn't exist. @command{Which} will consider two equivalent directories
269 to be different when one of them contains a path
270 with a symbolic link.
273 @node See Also, Index, Bugs, Top
280 @node Index, , See Also, Top
281 @comment node-name, next, previous, up