xref: /freebsd/usr.bin/which/which.1 (revision fa9896e082a1046ff4fbc75fcba4d18d1f2efc19)
1c5e7e03aSRuslan Ermilov.\" Manpage Copyright (c) 1995, Jordan Hubbard <jkh@FreeBSD.org>
29d6b1253SJordan K. Hubbard.\"
39d6b1253SJordan K. Hubbard.\" Redistribution and use in source and binary forms, with or without
49d6b1253SJordan K. Hubbard.\" modification, are permitted provided that the following conditions
59d6b1253SJordan K. Hubbard.\" are met:
69d6b1253SJordan K. Hubbard.\" 1. Redistributions of source code must retain the above copyright
79d6b1253SJordan K. Hubbard.\"    notice, this list of conditions and the following disclaimer.
89d6b1253SJordan K. Hubbard.\" 2. Redistributions in binary form must reproduce the above copyright
99d6b1253SJordan K. Hubbard.\"    notice, this list of conditions and the following disclaimer in the
109d6b1253SJordan K. Hubbard.\"    documentation and/or other materials provided with the distribution.
119d6b1253SJordan K. Hubbard.\" 3. All advertising materials mentioning features or use of this software
129d6b1253SJordan K. Hubbard.\"    must display the following acknowledgement:
139d6b1253SJordan K. Hubbard.\"      This product includes software developed by the FreeBSD Project
149d6b1253SJordan K. Hubbard.\"      its contributors.
159d6b1253SJordan K. Hubbard.\" 4. Neither the name of the FreeBSD Project nor the names of its contributors
169d6b1253SJordan K. Hubbard.\"    may be used to endorse or promote products derived from this software
179d6b1253SJordan K. Hubbard.\"    without specific prior written permission.
183819b413SWolfram Schneider.\"
199d6b1253SJordan K. Hubbard.\" THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTOR ``AS IS'' AND ANY EXPRESS OR
209d6b1253SJordan K. Hubbard.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
219d6b1253SJordan K. Hubbard.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
229d6b1253SJordan K. Hubbard.\" IN NO EVENT SHALL THE CONTRIBUTOR BE LIABLE FOR ANY DIRECT, INDIRECT,
239d6b1253SJordan K. Hubbard.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
249d6b1253SJordan K. Hubbard.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
259d6b1253SJordan K. Hubbard.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
269d6b1253SJordan K. Hubbard.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
279d6b1253SJordan K. Hubbard.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
289d6b1253SJordan K. Hubbard.\" OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
299d6b1253SJordan K. Hubbard.\"
30f0f718ceSFernando Apesteguía.Dd September 24, 2020
319d6b1253SJordan K. Hubbard.Dt WHICH 1
3262500372SRuslan Ermilov.Os
339d6b1253SJordan K. Hubbard.Sh NAME
349d6b1253SJordan K. Hubbard.Nm which
359d6b1253SJordan K. Hubbard.Nd "locate a program file in the user's path"
369d6b1253SJordan K. Hubbard.Sh SYNOPSIS
378fe908efSRuslan Ermilov.Nm
3835bff0b9SSatoshi Asami.Op Fl as
39b7a311f2SRuslan Ermilov.Ar program ...
409d6b1253SJordan K. Hubbard.Sh DESCRIPTION
41e8937ba0SPhilippe CharnierThe
42e8937ba0SPhilippe Charnier.Nm
43e8937ba0SPhilippe Charnierutility
449d6b1253SJordan K. Hubbardtakes a list of command names and searches the path for each executable
459d6b1253SJordan K. Hubbardfile that would be run had these commands actually been invoked.
4635bff0b9SSatoshi Asami.Pp
4735bff0b9SSatoshi AsamiThe following options are available:
4835bff0b9SSatoshi Asami.Bl -tag -width indent
4935bff0b9SSatoshi Asami.It Fl a
5035bff0b9SSatoshi AsamiList all instances of executables found (instead of just the first one
5135bff0b9SSatoshi Asamiof each).
5235bff0b9SSatoshi Asami.It Fl s
53531ab78aSRuslan ErmilovNo output, just return 0 if all of the executables are found, or 1 if
5422ae0cecSRuslan Ermilovsome were not found.
5521a6eb09SSheldon Hearn.El
56c644db6aSSheldon Hearn.Pp
57c644db6aSSheldon HearnSome shells may provide a builtin
58c644db6aSSheldon Hearn.Nm
59e6d3cf26SSheldon Hearncommand which is similar or identical to this utility.
60e6d3cf26SSheldon HearnConsult the
61c644db6aSSheldon Hearn.Xr builtin 1
62c644db6aSSheldon Hearnmanual page.
63f0f718ceSFernando Apesteguía.Sh EXAMPLES
64f0f718ceSFernando ApesteguíaLocate the
65f0f718ceSFernando Apesteguía.Xr ls 1
66f0f718ceSFernando Apesteguíaand
67f0f718ceSFernando Apesteguía.Xr cp 1
68f0f718ceSFernando Apesteguíacommands:
69f0f718ceSFernando Apesteguía.Bd -literal -offset indent
70f0f718ceSFernando Apesteguía$ /usr/bin/which ls cp
71f0f718ceSFernando Apesteguía/bin/ls
72f0f718ceSFernando Apesteguía/bin/cp
73f0f718ceSFernando Apesteguía.Ed
74f0f718ceSFernando Apesteguía.Pp
75f0f718ceSFernando ApesteguíaSame as above with a specific
76*347307b8SFernando Apesteguía.Ev PATH
77f0f718ceSFernando Apesteguíaand showing all occurrences:
78f0f718ceSFernando Apesteguía.Bd -literal -offset indent
79f0f718ceSFernando Apesteguía$ PATH=/bin:/rescue /usr/bin/which -a ls cp
80f0f718ceSFernando Apesteguía/bin/ls
81f0f718ceSFernando Apesteguía/rescue/ls
82f0f718ceSFernando Apesteguía/bin/cp
83f0f718ceSFernando Apesteguía/rescue/cp
84f0f718ceSFernando Apesteguía.Ed
85f0f718ceSFernando Apesteguía.Pp
86f0f718ceSFernando Apesteguía.Nm which
87*347307b8SFernando Apesteguíawill show duplicates if the same executable is found more than once:
88f0f718ceSFernando Apesteguía.Bd -literal -offset indent
89f0f718ceSFernando Apesteguía$ PATH=/bin:/bin /usr/bin/which -a ls
90f0f718ceSFernando Apesteguía/bin/ls
91f0f718ceSFernando Apesteguía/bin/ls
92f0f718ceSFernando Apesteguía.Ed
93f0f718ceSFernando Apesteguía.Pp
94f0f718ceSFernando ApesteguíaDo not show output.
95f0f718ceSFernando ApesteguíaJust exit with an appropriate return code:
96f0f718ceSFernando Apesteguía.Bd -literal -offset indent
97f0f718ceSFernando Apesteguía$ /usr/bin/which -s ls cp
98f0f718ceSFernando Apesteguía$ echo $?
99f0f718ceSFernando Apesteguía0
100f0f718ceSFernando Apesteguía
101f0f718ceSFernando Apesteguía$ /usr/bin/which -s fakecommand
102f0f718ceSFernando Apesteguía$ echo $?
103f0f718ceSFernando Apesteguía1
104f0f718ceSFernando Apesteguía.Ed
1059d6b1253SJordan K. Hubbard.Sh SEE ALSO
106c644db6aSSheldon Hearn.Xr builtin 1 ,
107c644db6aSSheldon Hearn.Xr csh 1 ,
10841cbb624SJoseph Koshy.Xr find 1 ,
10941cbb624SJoseph Koshy.Xr locate 1 ,
1106a34c725SJoseph Koshy.Xr whereis 1
1116c7216dfSRuslan Ermilov.Sh HISTORY
1126c7216dfSRuslan ErmilovThe
1136c7216dfSRuslan Ermilov.Nm
1146c7216dfSRuslan Ermilovcommand first appeared in
1156c7216dfSRuslan Ermilov.Fx 2.1 .
116306005e7SPhilippe Charnier.Sh AUTHORS
117ea2a88d9SRuslan Ermilov.An -nosplit
118ea2a88d9SRuslan ErmilovThe
11993a35425SPhilippe Charnier.Nm
120ea2a88d9SRuslan Ermilovutility was originally written in Perl and was contributed by
1212b7af31cSBaptiste Daroussin.An Wolfram Schneider Aq Mt wosch@FreeBSD.org .
122ea2a88d9SRuslan ErmilovThe current version of
123ea2a88d9SRuslan Ermilov.Nm
124ea2a88d9SRuslan Ermilovwas rewritten in C by
1252b7af31cSBaptiste Daroussin.An Daniel Papasian Aq Mt dpapasia@andrew.cmu.edu .
126