xref: /illumos-gate/usr/src/man/man1/which.1 (revision 8119dad84d6416f13557b0ba8e2aaf9064cbcfd3)
1.\"
2.\" Redistribution and use in source and binary forms, with or without
3.\" modification, are permitted provided that the following conditions
4.\" are met:
5.\" 1. Redistributions of source code must retain the above copyright
6.\"    notice, this list of conditions and the following disclaimer.
7.\" 2. Redistributions in binary form must reproduce the above copyright
8.\"    notice, this list of conditions and the following disclaimer in the
9.\"    documentation and/or other materials provided with the distribution.
10.\" 3. All advertising materials mentioning features or use of this software
11.\"    must display the following acknowledgement:
12.\"      This product includes software developed by the FreeBSD Project
13.\"      its contributors.
14.\" 4. Neither the name of the FreeBSD Project nor the names of its contributors
15.\"    may be used to endorse or promote products derived from this software
16.\"    without specific prior written permission.
17.\"
18.\" THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTOR ``AS IS'' AND ANY EXPRESS OR
19.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21.\" IN NO EVENT SHALL THE CONTRIBUTOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27.\" OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28.\"
29.\" Manpage Copyright (c) 1995, Jordan Hubbard <jkh@FreeBSD.org>
30.\" Copyright 2023 OmniOS Community Edition (OmniOSce) Association.
31.\"
32.Dd March 15, 2023
33.Dt WHICH 1
34.Os
35.Sh NAME
36.Nm which
37.Nd "locate a program file in the user's path"
38.Sh SYNOPSIS
39.Nm
40.Op Fl as
41.Ar command ...
42.Sh DESCRIPTION
43The
44.Nm
45utility
46takes a list of command names and searches the path for each executable
47file that would be run had these commands actually been invoked.
48.Pp
49Some shells may provide a built-in
50.Nm
51command which is similar or identical to this utility.
52.Sh OPTIONS
53The following options are available:
54.Bl -tag -width Ar
55.It Fl a
56List all instances of executables found
57.Pq instead of just the first one of each .
58.It Fl s
59No output, just return 0 if all of the executables are found, or 1 if
60some were not found.
61.El
62.Sh OPERANDS
63The following operands are supported:
64.Bl -tag -width Ar
65.It Ar command
66The name of a command to be located.
67.El
68.Sh ENVIRONMENT
69See
70.Xr environ 7
71for descriptions of the following environment variables that affect the
72execution of
73.Nm :
74.Ev PATH .
75.Sh EXIT STATUS
76The following exit values are returned:
77.Bl -tag -width Sy
78.It Sy 0
79All of the provided operands were found in the path and would be executed if
80the commands were invoked.
81.It Sy 1
82One or more of the provided operands was not found in the path or would not
83be executed if the commands were invoked, or an error occurred.
84.It Sy 2
85Invalid command line options were specified.
86.El
87.Sh EXAMPLES
88.Sy Example 1
89Locate the
90.Sq ls
91and
92.Sq cp
93commands.
94.Bd -literal -offset indent
95$ /usr/bin/which ls cp
96/usr/bin/ls
97/usr/bin/cp
98.Ed
99.Pp
100.Sy Example 2
101Use a specific
102.Ev PATH
103and show all occurrences.
104.Bd -literal -offset indent
105$ PATH=/usr/bin:/usr/has/bin /usr/bin/which -a edit
106/usr/bin/edit
107/usr/has/bin/edit
108.Ed
109.Pp
110.Sy Example 3
111Executable reported multiple times.
112.Pp
113If
114.Ev PATH
115contains repeated components, the same executable can be reported
116more than once:
117.Bd -literal -offset indent
118$ PATH=/usr/bin:/usr/bin /usr/bin/which -a ls
119/usr/bin/ls
120/usr/bin/ls
121.Ed
122.Pp
123.Sy Example 4
124Do not show output.
125.Pp
126Just exit with an appropriate return code:
127.Bd -literal -offset indent
128$ /usr/bin/which -s ls cp
129$ echo $?
1300
131$ /usr/bin/which -s fakecommand
132$ echo $?
1331
134.Ed
135.Sh INTERFACE STABILITY
136The command line interface of
137.Nm
138is
139.Sy Committed .
140The output of
141.Nm
142is
143.Sy Committed .
144.Sh SEE ALSO
145.Xr find 1 ,
146.Xr environ 7
147