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 18This file documents `which' version 2.x@. 19@c !END INTRO 20 21@c !BEGIN COPYING 22Copyright @copyright{} 2000 - 2015, by 23 24Carlo Wood, Run on IRC <carlo@@alinoe.com> 25RSA-1024 0x624ACAD5 1997-01-26 Sign & Encrypt 26Fingerprint16 = 32 EC A7 B6 AC DB 65 A6 F6 F6 55 DD 1C DC FF 61 27 28Permission is granted to make and distribute verbatim copies of 29this manual provided the copyright notice and this permission notice 30are preserved on all copies. 31@end format 32 33@ignore 34Permission is granted to copy and distribute modified versions of this 35manual under the conditions for verbatim copying, provided also that the 36section entitled ``GNU General Public License'' is included exactly as 37in the original, and provided that the entire resulting derived work is 38distributed under the terms of a permission notice identical to this 39one. 40 41Permission is granted to copy and distribute translations of this manual 42into another language, under the above conditions for modified versions, 43except that the section entitled ``GNU General Public License'' may be 44included in a translation approved by the author instead of in the 45original 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 61Copyright @copyright{} 2000 - 2015, by 62 63Carlo Wood, Run on IRC <carlo@@alinoe.com> 64RSA-1024 0x624ACAD5 1997-01-26 Sign & Encrypt 65Fingerprint16 = 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 75The @command{which} program 76@c !BEGIN NAME 77shows the full path of (shell) commands. 78@c !END NAME 79 80@noindent 81This 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 101it prints to stdout the full path of the executables 102that would have been executed when this argument had been 103entered at the shell prompt. It does this by searching 104for an executable or script in the directories listed in 105the 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 114The synopsis to invoke @command{which} is 115 116@c !BEGIN SYNOPSIS 117@example 118which [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 138Print 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 144Read aliases from stdin, reporting matching ones on 145stdout. This is useful in combination with using an 146alias for which itself. For example@* 147@code{alias which='alias | which -i'}. 148 149@cindex @option{--skip-alias} 150@item --skip-alias 151Ignore option @option{--read-alias}, if any. This is useful to 152explicity search for normal binaries, while using 153the @option{--read-alias} option in an alias or function for which. 154 155@cindex @option{--read-functions} 156@item --read-functions 157Read shell function definitions from stdin, reporting matching 158ones on stdout. This is useful in combination with using a shell 159function 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 164Ignore option @option{--read-functions}, if any. This is useful to 165explicity search for normal binaries, while using 166the @option{--read-functions} option in an alias or function for which. 167 168@cindex @option{--skip-dot} 169@item --skip-dot 170Skip directories in @env{PATH} that start with a dot. 171 172@cindex @option{--skip-tilde} 173@item --skip-tilde 174Skip directories in @env{PATH} that start with a tilde and 175executables which reside in the @env{HOME} directory. 176 177@cindex @option{--show-dot} 178@item --show-dot 179If a directory in @env{PATH} starts with a dot and a matching 180executable was found for that path, then print 181"./programname" rather than the full path. 182 183@cindex @option{--show-tilde} 184@item --show-tilde 185Output a tilde when a directory matches the @env{HOME} 186directory. This option is ignored when which is 187invoked as root. 188 189@cindex @option{--tty-only} 190@item --tty-only 191Stop 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 197Print version information on standard output then exit 198successfully. 199 200@cindex @option{--help} 201@item --help 202Print usage information on standard output then exit 203successfully. 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 214no @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 223The recommended way to use this utility is by adding an alias (C shell) 224or shell function (Bourne shell) for @command{which} like the following: 225 226[ba]sh: 227 228@example 229@group 230which () 231@{ 232 (alias; declare -f) | /usr/bin/which --tty-only --read-alias --read-functions --show-tilde --show-dot $@@ 233@} 234export -f which 235@end group 236@end example 237 238[t]csh: 239 240@example 241@group 242alias which 'alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde' 243@end group 244@end example 245 246@noindent 247This will print the readable ~/ and ./ when starting which 248from your prompt, while still printing the full path when 249used 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 266The @env{HOME} directory is determined by looking for the @env{HOME} 267environment variable, which aborts when this variable 268doesn't exist. @command{Which} will consider two equivalent directories 269to be different when one of them contains a path 270with 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 288