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