OSDN Git Service

5c6221493bda16af6505c7d3e723745c6696e321
[linuxjm/jm.git] / info / GNU_which / original / texi / which.texi
1 \input texinfo   @c -*-texinfo-*-
2 @c %**start of header
3 @setfilename which.info
4 @settitle @command{which}: show full path of commands
5 @include version.texi
6 @dircategory System administration
7 @direntry
8 * Which: (which).                               Show full path of commands.
9 @end direntry
10 @c %**end of header
11
12 @setchapternewpage odd
13
14 @ifinfo
15 @format
16
17 @c !BEGIN INTRO
18 This file documents `which' version 2.x@.
19 @c !END INTRO
20
21 @c !BEGIN COPYING
22 Copyright @copyright{} 2000 - 2015, by
23
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
27
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.
31 @end format
32
33 @ignore
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
39 one.
40
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
45 original English.
46 @end ignore
47 @c !END COPYING
48 @end ifinfo
49
50 @titlepage
51 @title Which
52 @subtitle Show the full path of commands
53 @sp 1
54 @subtitle Edition @value{EDITION}, for Which Version @value{VERSION}
55 @subtitle @value{UPDATED}
56 @c !BEGIN AUTHORS
57 @author Carlo Wood <@email{carlo@@gnu.org}>
58 @c !END AUTHORS
59 @page
60 @vskip 0pt plus 1filll
61 Copyright @copyright{} 2000 - 2015, by
62
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
66
67 @end titlepage
68
69 @ifnottex
70 @node Top, Which Program, (dir), (dir)
71 @top @command{which}: Show the full path of commands
72 @end ifnottex
73
74 @ifinfo
75 The @command{which} program
76 @c !BEGIN NAME
77 shows the full path of (shell) commands.
78 @c !END NAME
79
80 @noindent
81 This file documents @command{which} version @value{VERSION}, updated @value{UPDATED}.
82 @end ifinfo
83
84 @menu
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
90 * Bugs::                        Known bugs
91 * See Also::                    Related UNIX commands
92 * Index::                       Index
93 @end menu
94
95 @node Which Program, Invoking Which, Top, Top
96 @chapter The @command{which} Program
97 @cindex Description of @command{which}
98
99 @c !BEGIN DESCRIPTION
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)}.
106 @c !END DESCRIPTION
107
108 @node    Invoking Which, Option Summary, Which Program, Top
109 @chapter Invoking @command{which}
110 @cindex Invoking @command{which}
111 @cindex Synopsis
112
113 @noindent
114 The synopsis to invoke @command{which} is
115
116 @c !BEGIN SYNOPSIS
117 @example
118 which [options] [--] programname [...]
119 @end example
120 @c !END SYNOPSIS
121
122 @menu
123 * Option Summary::        Option summary
124 @end menu
125
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
131
132 @c !BEGIN OPTIONS
133 @table @samp
134 @cindex @option{--all}
135 @cindex @option{-a}
136 @item --all
137 @itemx -a
138 Print all matching executables in @env{PATH}, not just the first.
139
140 @cindex @option{--read-alias}
141 @cindex @option{-i}
142 @item --read-alias
143 @itemx -i
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'}.
148
149 @cindex @option{--skip-alias}
150 @item --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.
154
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}
161
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.
167
168 @cindex @option{--skip-dot}
169 @item --skip-dot
170 Skip directories in @env{PATH} that start with a dot.
171
172 @cindex @option{--skip-tilde}
173 @item --skip-tilde
174 Skip directories in @env{PATH} that start with a tilde and
175 executables which reside in the @env{HOME} directory.
176
177 @cindex @option{--show-dot}
178 @item --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.
182
183 @cindex @option{--show-tilde}
184 @item --show-tilde
185 Output a tilde when a directory matches the @env{HOME}
186 directory. This option is ignored when which is
187 invoked as root.
188
189 @cindex @option{--tty-only}
190 @item --tty-only
191 Stop processing options on the right if not on tty.
192
193 @cindex @option{--version}
194 @cindex @option{-v}
195 @cindex @option{-V}
196 @item --version, -v, -V
197 Print version information on standard output then exit
198 successfully.
199
200 @cindex @option{--help}
201 @item --help
202 Print usage information on standard output then exit
203 successfully.
204
205 @end table
206 @c !END OPTIONS
207
208 @node    Return Value, Example, Option Summary, Top
209 @chapter Return Value
210 @cindex Return value of @command{which}
211
212 @c !BEGIN RETURNVALUE
213 @command{Which} returns the number of failed arguments, or -1 when
214 no @file{programname} was given.
215 @c !END RETURNVALUE
216
217 @node    Example, Bugs, Return Value, Top
218 @chapter Example
219 @cindex Examples
220 @cindex aliases, handling of
221
222 @c !BEGIN EXAMPLE
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:
225
226 [ba]sh:
227
228 @example
229 @group
230 which ()
231 @{
232   (alias; declare -f) | /usr/bin/which --tty-only --read-alias --read-functions --show-tilde --show-dot $@@
233 @}
234 export -f which
235 @end group
236 @end example
237
238 [t]csh:
239
240 @example
241 @group
242 alias which 'alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
243 @end group
244 @end example
245
246 @noindent
247 This will print the readable ~/ and ./ when starting which
248 from your prompt, while still printing the full path when
249 used from a script:
250
251 @example
252 @group
253 > which q2
254 ~/bin/q2
255 > echo `which q2`
256 /home/carlo/bin/q2
257 @end group
258 @end example
259 @c !END EXAMPLE
260
261 @node    Bugs, See Also, Example, Top
262 @chapter Bugs
263 @cindex Bugs, known
264
265 @c !BEGIN BUGS
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.
271 @c !END BUGS
272
273 @node    See Also, Index, Bugs, Top
274 @chapter See Also
275
276 @c !BEGIN SEEALSO
277 @command{bash(1)}
278 @c !END SEEALSO
279
280 @node    Index,            ,  See Also, Top
281 @comment node-name,    next,  previous,       up
282 @unnumbered Index
283
284 @printindex cp
285
286 @contents
287 @bye