1WHICH(1)                    General Commands Manual                   WHICH(1)
2
3
4

NAME

6       which - shows the full path of (shell) commands.
7

SYNOPSIS

9       which [options] [--] programname [...]
10

DESCRIPTION

12       Which takes one or more arguments. For each of its arguments it prints
13       to stdout the full path of the executables that would have been exe‐
14       cuted when this argument had been entered at the shell prompt. It does
15       this by searching for an executable or script in the directories listed
16       in the environment variable PATH using the same algorithm as bash(1).
17
18       This man page is generated from the file which.texinfo.
19

OPTIONS

21       --all, -a
22           Print all matching executables in PATH, not just the first.
23
24       --read-alias, -i
25           Read aliases from stdin, reporting matching ones on stdout. This is
26           useful in combination with using an alias for which itself. For
27           example
28           alias which=´alias | which -i´.
29
30       --skip-alias
31           Ignore option `--read-alias´, if any. This is useful to explicity
32           search for normal binaries, while using the `--read-alias´ option
33           in an alias or function for which.
34
35       --read-functions
36           Read shell function definitions from stdin, reporting matching ones
37           on stdout. This is useful in combination with using a shell func‐
38           tion for which itself.  For example:
39           which() { declare -f | which --read-functions $@ }
40           export -f which
41
42       --skip-functions
43           Ignore option `--read-functions´, if any. This is useful to explic‐
44           ity search for normal binaries, while using the `--read-functions´
45           option in an alias or function for which.
46
47       --skip-dot
48           Skip directories in PATH that start with a dot.
49
50       --skip-tilde
51           Skip directories in PATH that start with a tilde and executables
52           which reside in the HOME directory.
53
54       --show-dot
55           If a directory in PATH starts with a dot and a matching executable
56           was found for that path, then print "./programname" rather than the
57           full path.
58
59       --show-tilde
60           Output a tilde when a directory matches the HOME directory. This
61           option is ignored when which is invoked as root.
62
63       --tty-only
64           Stop processing options on the right if not on tty.
65
66       --version,-v,-V
67           Print version information on standard output then exit success‐
68           fully.
69
70       --help
71           Print usage information on standard output then exit successfully.
72

RETURN VALUE

74       Which returns the number of failed arguments, or -1 when no `program‐
75       name´ was given.
76

EXAMPLE

78       The recommended way to use this utility is by adding an alias (C shell)
79       or shell function (Bourne shell) for which like the following:
80
81       [ba]sh:
82
83            which ()
84            {
85              (alias; declare -f) | /usr/bin/which --tty-only --read-alias --read-functions --show-tilde --show-dot $@
86            }
87            export -f which
88
89       [t]csh:
90
91            alias which ´alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde´
92
93       This will print the readable ~/ and ./ when starting  which  from  your
94       prompt, while still printing the full path when used from a script:
95
96            > which q2
97            ~/bin/q2
98            > echo `which q2`
99            /home/carlo/bin/q2
100
101

BUGS

103       The  HOME  directory  is determined by looking for the HOME environment
104       variable, which aborts when this variable doesn´t  exist.   Which  will
105       consider  two  equivalent  directories to be different when one of them
106       contains a path with a symbolic link.
107

AUTHOR

109       Carlo Wood <carlo@gnu.org>
110

SEE ALSO

112       bash(1)
113
114
115
116                                                                      WHICH(1)
Impressum