xref: /freebsd-src/usr.bin/env/env.1 (revision 6f6166e49c78f6460732c02bbbba6fcc218221cf)
114f566d3STim J. Robbins.\" Copyright (c) 1980, 1990, 1993
214f566d3STim J. Robbins.\"	The Regents of the University of California.  All rights reserved.
314f566d3STim J. Robbins.\"
414f566d3STim J. Robbins.\" This code is derived from software contributed to Berkeley by
514f566d3STim J. Robbins.\" the Institute of Electrical and Electronics Engineers, Inc.
614f566d3STim J. Robbins.\" Redistribution and use in source and binary forms, with or without
714f566d3STim J. Robbins.\" modification, are permitted provided that the following conditions
814f566d3STim J. Robbins.\" are met:
914f566d3STim J. Robbins.\" 1. Redistributions of source code must retain the above copyright
1014f566d3STim J. Robbins.\"    notice, this list of conditions and the following disclaimer.
1114f566d3STim J. Robbins.\" 2. Redistributions in binary form must reproduce the above copyright
1214f566d3STim J. Robbins.\"    notice, this list of conditions and the following disclaimer in the
1314f566d3STim J. Robbins.\"    documentation and/or other materials provided with the distribution.
14fbbd9655SWarner Losh.\" 3. Neither the name of the University nor the names of its contributors
1514f566d3STim J. Robbins.\"    may be used to endorse or promote products derived from this software
1614f566d3STim J. Robbins.\"    without specific prior written permission.
1714f566d3STim J. Robbins.\"
1814f566d3STim J. Robbins.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
1914f566d3STim J. Robbins.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2014f566d3STim J. Robbins.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2114f566d3STim J. Robbins.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2214f566d3STim J. Robbins.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2314f566d3STim J. Robbins.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2414f566d3STim J. Robbins.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2514f566d3STim J. Robbins.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2614f566d3STim J. Robbins.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2714f566d3STim J. Robbins.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2814f566d3STim J. Robbins.\" SUCH DAMAGE.
2914f566d3STim J. Robbins.\" From FreeBSD: src/usr.bin/printenv/printenv.1,v 1.17 2002/11/26 17:33:35 ru Exp
3014f566d3STim J. Robbins.\"
31*6f6166e4SDag-Erling Smørgrav.Dd October 8, 2024
3214f566d3STim J. Robbins.Dt ENV 1
3314f566d3STim J. Robbins.Os
3414f566d3STim J. Robbins.Sh NAME
3514f566d3STim J. Robbins.Nm env
3668ef2072SGarance A Drosehn.Nd set environment and execute command, or print environment
3714f566d3STim J. Robbins.Sh SYNOPSIS
3814f566d3STim J. Robbins.Nm
395e5ceb11SJoseph Mingrone.Op Fl 0iv
4085c8521eSKyle Evans.Op Fl L Ns | Ns Fl U Ar user Ns Op / Ns Ar class
41a4848c10SMateusz Piotrowski.Op Fl u Ar name
42a4848c10SMateusz Piotrowski.Op Ar name Ns = Ns Ar value ...
43a4848c10SMateusz Piotrowski.Nm
44a4848c10SMateusz Piotrowski.Op Fl iv
45*6f6166e4SDag-Erling Smørgrav.Op Fl C Ar altwd
46a4848c10SMateusz Piotrowski.Op Fl L Ns | Ns Fl U Ar user Ns Op / Ns Ar class
478fbe7ebfSGarance A Drosehn.Op Fl P Ar altpath
488fbe7ebfSGarance A Drosehn.Op Fl S Ar string
49a414225dSGarance A Drosehn.Op Fl u Ar name
5014f566d3STim J. Robbins.Op Ar name Ns = Ns Ar value ...
51a4848c10SMateusz Piotrowski.Ar utility Op Ar argument ...
5214f566d3STim J. Robbins.Sh DESCRIPTION
5314f566d3STim J. RobbinsThe
5414f566d3STim J. Robbins.Nm
55607e48e7SRuslan Ermilovutility executes another
5614f566d3STim J. Robbins.Ar utility
5714f566d3STim J. Robbinsafter modifying the environment as
5814f566d3STim J. Robbinsspecified on the command line.
598fbe7ebfSGarance A DrosehnEach
6014f566d3STim J. Robbins.Ar name Ns = Ns Ar value
618fbe7ebfSGarance A Drosehnoption specifies the setting of an environment variable,
6214f566d3STim J. Robbins.Ar name ,
6314f566d3STim J. Robbinswith a value of
6414f566d3STim J. Robbins.Ar value .
658fbe7ebfSGarance A DrosehnAll such environment variables are set before the
668fbe7ebfSGarance A Drosehn.Ar utility
678fbe7ebfSGarance A Drosehnis executed.
6814f566d3STim J. Robbins.Pp
6914f566d3STim J. RobbinsThe options are as follows:
7014f566d3STim J. Robbins.Bl -tag -width indent
715e5ceb11SJoseph Mingrone.It Fl 0
725e5ceb11SJoseph MingroneEnd each output line with NUL, not newline.
7314f566d3STim J. Robbins.It Fl i
7414f566d3STim J. RobbinsExecute the
7514f566d3STim J. Robbins.Ar utility
768fbe7ebfSGarance A Drosehnwith only those environment variables specified by
778fbe7ebfSGarance A Drosehn.Ar name Ns = Ns Ar value
788fbe7ebfSGarance A Drosehnoptions.
7914f566d3STim J. RobbinsThe environment inherited
8014f566d3STim J. Robbinsby
8152964a40SRuslan Ermilov.Nm
8214f566d3STim J. Robbinsis ignored completely.
83*6f6166e4SDag-Erling Smørgrav.\"     -C
84*6f6166e4SDag-Erling Smørgrav.It Fl C Ar altwd
85*6f6166e4SDag-Erling SmørgravChange to the specified alternate working directory before executing
86*6f6166e4SDag-Erling Smørgravthe specified
87*6f6166e4SDag-Erling Smørgrav.Ar utility
88*6f6166e4SDag-Erling Smørgravprogram.
8985c8521eSKyle Evans.\"	-L | -U
9085c8521eSKyle Evans.It Fl L | Fl U Ar user Ns Op / Ns Ar class
9185c8521eSKyle EvansAdd the environment variable definitions from
9285c8521eSKyle Evans.Xr login.conf 5
9385c8521eSKyle Evansfor the specified user and login class to the environment, after
9485c8521eSKyle Evansprocessing any
9585c8521eSKyle Evans.Fl i
9685c8521eSKyle Evansor
9785c8521eSKyle Evans.Fl u
9885c8521eSKyle Evansoptions, but before processing any
9985c8521eSKyle Evans.Ar name Ns = Ns Ar value
10085c8521eSKyle Evansoptions.
10185c8521eSKyle EvansIf
10285c8521eSKyle Evans.Fl L
10385c8521eSKyle Evansis used, only the system-wide
10485c8521eSKyle Evans.Pa /etc/login.conf.db
10585c8521eSKyle Evansfile is read; if
10685c8521eSKyle Evans.Fl U
10785c8521eSKyle Evansis used, then the specified user's
10885c8521eSKyle Evans.Pa ~/.login_conf
10985c8521eSKyle Evansis read as well.
11085c8521eSKyle EvansThe user may be specified by name or by uid.
11155deb0a5SAndrew GierthIf a username of
11255deb0a5SAndrew Gierth.Sq Li \&-
11355deb0a5SAndrew Gierthis given, then no user lookup will be done, the login class will default to
11455deb0a5SAndrew Gierth.Sq Li default
11555deb0a5SAndrew Gierthif not explicitly given, and no substitutions will be done on the values.
1168fbe7ebfSGarance A Drosehn.\"	-P
1178fbe7ebfSGarance A Drosehn.It Fl P Ar altpath
1188fbe7ebfSGarance A DrosehnSearch the set of directories as specified by
1198fbe7ebfSGarance A Drosehn.Ar altpath
1208fbe7ebfSGarance A Drosehnto locate the specified
1218fbe7ebfSGarance A Drosehn.Ar utility
1225dea8a44SRuslan Ermilovprogram, instead of using the value of the
1235dea8a44SRuslan Ermilov.Ev PATH
1245dea8a44SRuslan Ermilovenvironment variable.
1258fbe7ebfSGarance A Drosehn.\"	-S
1268fbe7ebfSGarance A Drosehn.It Fl S Ar string
1278fbe7ebfSGarance A DrosehnSplit apart the given
1288fbe7ebfSGarance A Drosehn.Ar string
1298fbe7ebfSGarance A Drosehninto multiple strings, and process each of the resulting strings
1308fbe7ebfSGarance A Drosehnas separate arguments to the
1318fbe7ebfSGarance A Drosehn.Nm
1328fbe7ebfSGarance A Drosehnutility.
1338fbe7ebfSGarance A DrosehnThe
1348fbe7ebfSGarance A Drosehn.Fl S
1358fbe7ebfSGarance A Drosehnoption recognizes some special character escape sequences and
1368fbe7ebfSGarance A Drosehnalso supports environment-variable substitution, as described
1378fbe7ebfSGarance A Drosehnbelow.
138a414225dSGarance A Drosehn.\"	-u
139a414225dSGarance A Drosehn.It Fl u Ar name
140a414225dSGarance A DrosehnIf the environment variable
141a414225dSGarance A Drosehn.Ar name
142a414225dSGarance A Drosehnis in the environment, then remove it before processing the
143a414225dSGarance A Drosehnremaining options.
144a414225dSGarance A DrosehnThis is similar to the
145a414225dSGarance A Drosehn.Ic unset
146a414225dSGarance A Drosehncommand in
147a414225dSGarance A Drosehn.Xr sh 1 .
148a414225dSGarance A DrosehnThe value for
149a414225dSGarance A Drosehn.Ar name
150a414225dSGarance A Drosehnmust not include the
151a414225dSGarance A Drosehn.Ql =
152a414225dSGarance A Drosehncharacter.
1538fbe7ebfSGarance A Drosehn.\"	-v
1548fbe7ebfSGarance A Drosehn.It Fl v
1558fbe7ebfSGarance A DrosehnPrint verbose information for each step of processing done by the
1568fbe7ebfSGarance A Drosehn.Nm
1578fbe7ebfSGarance A Drosehnutility.
1588fbe7ebfSGarance A DrosehnAdditional information will be printed if
1598fbe7ebfSGarance A Drosehn.Fl v
1608fbe7ebfSGarance A Drosehnis specified multiple times.
16114f566d3STim J. Robbins.El
16214f566d3STim J. Robbins.Pp
1638fbe7ebfSGarance A DrosehnThe above options are only recognized when they are specified
1648fbe7ebfSGarance A Drosehnbefore any
1658fbe7ebfSGarance A Drosehn.Ar name Ns = Ns Ar value
1668fbe7ebfSGarance A Drosehnoptions.
1678fbe7ebfSGarance A Drosehn.Pp
168607e48e7SRuslan ErmilovIf no
169607e48e7SRuslan Ermilov.Ar utility
170607e48e7SRuslan Ermilovis specified,
17152964a40SRuslan Ermilov.Nm
1725e5ceb11SJoseph Mingroneprints out the names and values of the variables in the environment.
1735e5ceb11SJoseph MingroneEach name/value pair is separated by a new line unless
1745e5ceb11SJoseph Mingrone.Fl 0
1755e5ceb11SJoseph Mingroneis specified, in which case name/value pairs are separated by NUL.
1765e5ceb11SJoseph MingroneBoth
1775e5ceb11SJoseph Mingrone.Fl 0
1785e5ceb11SJoseph Mingroneand
1795e5ceb11SJoseph Mingrone.Ar utility
1805e5ceb11SJoseph Mingronemay not be specified together.
181a0dfb066SDag-Erling Smørgrav.Pp
182a0dfb066SDag-Erling SmørgravThe
183a0dfb066SDag-Erling Smørgrav.Nm
184a0dfb066SDag-Erling Smørgravutility does not handle values of
185a0dfb066SDag-Erling Smørgrav.Ar utility
186a0dfb066SDag-Erling Smørgravwhich have an equals sign
187a0dfb066SDag-Erling Smørgrav.Pq Ql =
188a0dfb066SDag-Erling Smørgravin their name, for obvious reasons.
189a0dfb066SDag-Erling SmørgravThis can easily be worked around by interposing the
190a0dfb066SDag-Erling Smørgrav.Xr command 1
191a0dfb066SDag-Erling Smørgravutility, which simply executes its arguments; see
192a0dfb066SDag-Erling Smørgrav.Sx EXAMPLES
193a0dfb066SDag-Erling Smørgravbelow.
1948fbe7ebfSGarance A Drosehn.\"
195beb71006SMateusz Piotrowski.Ss Details of -S (split-string) processing
1968fbe7ebfSGarance A DrosehnThe processing of the
1978fbe7ebfSGarance A Drosehn.Fl S
1988fbe7ebfSGarance A Drosehnoption will split the given
1998fbe7ebfSGarance A Drosehn.Ar string
2008fbe7ebfSGarance A Drosehninto separate arguments based on any space or <tab> characters found in the
2018fbe7ebfSGarance A Drosehn.Ar string .
2028fbe7ebfSGarance A DrosehnEach of those new arguments will then be treated as if it had been
2038fbe7ebfSGarance A Drosehnspecified as a separate argument on the original
2048fbe7ebfSGarance A Drosehn.Nm
2058fbe7ebfSGarance A Drosehncommand.
2068fbe7ebfSGarance A Drosehn.Pp
2078fbe7ebfSGarance A DrosehnSpaces and tabs may be embedded in one of those new arguments by using
2085dea8a44SRuslan Ermilovsingle
2095dea8a44SRuslan Ermilov.Pq Dq Li '
2105dea8a44SRuslan Ermilovor double
2115dea8a44SRuslan Ermilov.Pq Ql \&"
2125dea8a44SRuslan Ermilovquotes, or backslashes
2135dea8a44SRuslan Ermilov.Pq Ql \e .
2148fbe7ebfSGarance A DrosehnSingle quotes will escape all non-single quote characters, up to
2158fbe7ebfSGarance A Drosehnthe matching single quote.
2168fbe7ebfSGarance A DrosehnDouble quotes will escape all non-double quote characters, up to
2178fbe7ebfSGarance A Drosehnthe matching double quote.
2188fbe7ebfSGarance A DrosehnIt is an error if the end of the
2198fbe7ebfSGarance A Drosehn.Ar string
2208fbe7ebfSGarance A Drosehnis reached before the matching quote character.
2218fbe7ebfSGarance A Drosehn.Pp
2228fbe7ebfSGarance A DrosehnIf
2238fbe7ebfSGarance A Drosehn.Fl S
2248fbe7ebfSGarance A Drosehnwould create a new argument that starts with the
2258fbe7ebfSGarance A Drosehn.Ql #
2268fbe7ebfSGarance A Drosehncharacter, then that argument and the remainder of the
2278fbe7ebfSGarance A Drosehn.Ar string
2288fbe7ebfSGarance A Drosehnwill be ignored.
2298fbe7ebfSGarance A DrosehnThe
2308fbe7ebfSGarance A Drosehn.Ql \e#
2318fbe7ebfSGarance A Drosehnsequence can be used when you want a new argument to start
2328fbe7ebfSGarance A Drosehnwith a
2338fbe7ebfSGarance A Drosehn.Ql #
2348fbe7ebfSGarance A Drosehncharacter, without causing the remainder of the
2358fbe7ebfSGarance A Drosehn.Ar string
2368fbe7ebfSGarance A Drosehnto be skipped.
2378fbe7ebfSGarance A Drosehn.Pp
2388fbe7ebfSGarance A DrosehnWhile processing the
2398fbe7ebfSGarance A Drosehn.Ar string
2408fbe7ebfSGarance A Drosehnvalue,
2418fbe7ebfSGarance A Drosehn.Fl S
2428fbe7ebfSGarance A Drosehnprocessing will treat certain character combinations as escape
2438fbe7ebfSGarance A Drosehnsequences which represent some action to take.
2448fbe7ebfSGarance A DrosehnThe character escape sequences are in backslash notation.
2458fbe7ebfSGarance A DrosehnThe characters and their meanings are as follows:
2468fbe7ebfSGarance A Drosehn.Pp
2475dea8a44SRuslan Ermilov.Bl -tag -width indent -offset indent -compact
2488fbe7ebfSGarance A Drosehn.It Cm \ec
2498fbe7ebfSGarance A DrosehnIgnore the remaining characters in the
2508fbe7ebfSGarance A Drosehn.Ar string .
2518fbe7ebfSGarance A DrosehnThis must not appear inside a double-quoted string.
2528fbe7ebfSGarance A Drosehn.It Cm \ef
2538fbe7ebfSGarance A DrosehnReplace with a <form-feed> character.
2548fbe7ebfSGarance A Drosehn.It Cm \en
2558fbe7ebfSGarance A DrosehnReplace with a <new-line> character.
2568fbe7ebfSGarance A Drosehn.It Cm \er
2578fbe7ebfSGarance A DrosehnReplace with a <carriage return> character.
2588fbe7ebfSGarance A Drosehn.It Cm \et
2598fbe7ebfSGarance A DrosehnReplace with a <tab> character.
2608fbe7ebfSGarance A Drosehn.It Cm \ev
2618fbe7ebfSGarance A DrosehnReplace with a <vertical tab> character.
2628fbe7ebfSGarance A Drosehn.It Cm \e#
2638fbe7ebfSGarance A DrosehnReplace with a
2648fbe7ebfSGarance A Drosehn.Ql #
2658fbe7ebfSGarance A Drosehncharacter.
2668fbe7ebfSGarance A DrosehnThis would be useful when you need a
2678fbe7ebfSGarance A Drosehn.Ql #
2688fbe7ebfSGarance A Drosehnas the first character in one of the arguments created
2698fbe7ebfSGarance A Drosehnby splitting apart the given
2708fbe7ebfSGarance A Drosehn.Ar string .
2718fbe7ebfSGarance A Drosehn.It Cm \e$
2728fbe7ebfSGarance A DrosehnReplace with a
2738fbe7ebfSGarance A Drosehn.Ql $
2748fbe7ebfSGarance A Drosehncharacter.
2758fbe7ebfSGarance A Drosehn.It Cm \e_
2768fbe7ebfSGarance A DrosehnIf this is found inside of a double-quoted string, then replace it
2778fbe7ebfSGarance A Drosehnwith a single blank.
2788fbe7ebfSGarance A DrosehnIf this is found outside of a quoted string, then treat this as the
2798fbe7ebfSGarance A Drosehnseparator character between new arguments in the original
2808fbe7ebfSGarance A Drosehn.Ar string .
2818fbe7ebfSGarance A Drosehn.It Cm \e"
2828fbe7ebfSGarance A DrosehnReplace with a <double quote> character.
2838fbe7ebfSGarance A Drosehn.It Cm \e\'
2848fbe7ebfSGarance A DrosehnReplace with a <single quote> character.
2858fbe7ebfSGarance A Drosehn.It Cm \e\e
2868fbe7ebfSGarance A DrosehnReplace with a backslash character.
2878fbe7ebfSGarance A Drosehn.El
2888fbe7ebfSGarance A Drosehn.Pp
2898fbe7ebfSGarance A DrosehnThe sequences for <single-quote> and backslash are the only sequences
2908fbe7ebfSGarance A Drosehnwhich are recognized inside of a single-quoted string.
2918fbe7ebfSGarance A DrosehnThe other sequences have no special meaning inside a single-quoted
2928fbe7ebfSGarance A Drosehnstring.
2938fbe7ebfSGarance A DrosehnAll escape sequences are recognized inside of a double-quoted string.
2948fbe7ebfSGarance A DrosehnIt is an error if a single
2958fbe7ebfSGarance A Drosehn.Ql \e
2968fbe7ebfSGarance A Drosehncharacter is followed by a character other than the ones listed above.
2978fbe7ebfSGarance A Drosehn.Pp
2988fbe7ebfSGarance A DrosehnThe processing of
2998fbe7ebfSGarance A Drosehn.Fl S
3008fbe7ebfSGarance A Drosehnalso supports substitution of values from environment variables.
3018fbe7ebfSGarance A DrosehnTo do this, the name of the environment variable must be inside of
3028fbe7ebfSGarance A Drosehn.Ql ${} ,
3035dea8a44SRuslan Ermilovsuch as:
3045dea8a44SRuslan Ermilov.Li ${SOMEVAR} .
3055dea8a44SRuslan ErmilovThe common shell syntax of
3065dea8a44SRuslan Ermilov.Li $SOMEVAR
3075dea8a44SRuslan Ermilovis not supported.
3088fbe7ebfSGarance A DrosehnAll values substituted will be the values of the environment variables
3098fbe7ebfSGarance A Drosehnas they were when the
3108fbe7ebfSGarance A Drosehn.Nm
3118fbe7ebfSGarance A Drosehnutility was originally invoked.
3128fbe7ebfSGarance A DrosehnThose values will not be checked for any of the escape sequences as
3138fbe7ebfSGarance A Drosehndescribed above.
3148fbe7ebfSGarance A DrosehnAnd any settings of
3158fbe7ebfSGarance A Drosehn.Ar name Ns = Ns Ar value
3168fbe7ebfSGarance A Drosehnwill not effect the values used for substitution in
3178fbe7ebfSGarance A Drosehn.Fl S
3188fbe7ebfSGarance A Drosehnprocessing.
3198fbe7ebfSGarance A Drosehn.Pp
3208fbe7ebfSGarance A DrosehnAlso,
3218fbe7ebfSGarance A Drosehn.Fl S
3228fbe7ebfSGarance A Drosehnprocessing cannot reference the value of the special parameters
3238fbe7ebfSGarance A Drosehnwhich are defined by most shells.
3248fbe7ebfSGarance A DrosehnFor instance,
3258fbe7ebfSGarance A Drosehn.Fl S
3268fbe7ebfSGarance A Drosehncannot recognize special parameters such as:
3278fbe7ebfSGarance A Drosehn.Ql $* ,
3288fbe7ebfSGarance A Drosehn.Ql $@ ,
3298fbe7ebfSGarance A Drosehn.Ql $# ,
3308fbe7ebfSGarance A Drosehn.Ql $?
3318fbe7ebfSGarance A Drosehnor
3328fbe7ebfSGarance A Drosehn.Ql $$
3338fbe7ebfSGarance A Drosehnif they appear inside the given
3348fbe7ebfSGarance A Drosehn.Ar string .
3358fbe7ebfSGarance A Drosehn.\"
3368fbe7ebfSGarance A Drosehn.Ss Use in shell-scripts
3378fbe7ebfSGarance A DrosehnThe
3388fbe7ebfSGarance A Drosehn.Nm
3398fbe7ebfSGarance A Drosehnutility is often used as the
3408fbe7ebfSGarance A Drosehn.Ar interpreter
3418fbe7ebfSGarance A Drosehnon the first line of interpreted scripts, as
3428fbe7ebfSGarance A Drosehndescribed in
3438fbe7ebfSGarance A Drosehn.Xr execve 2 .
3448fbe7ebfSGarance A Drosehn.Pp
3458fbe7ebfSGarance A DrosehnNote that the way the kernel parses the
3468fbe7ebfSGarance A Drosehn.Ql #!
3478fbe7ebfSGarance A Drosehn(first line) of an interpreted script has changed as of
3488fbe7ebfSGarance A Drosehn.Fx 6.0 .
3498fbe7ebfSGarance A DrosehnPrior to that, the
3508fbe7ebfSGarance A Drosehn.Fx
3518fbe7ebfSGarance A Drosehnkernel would split that first line into separate arguments based
3528fbe7ebfSGarance A Drosehnon any whitespace (space or <tab> characters) found in the line.
3538fbe7ebfSGarance A DrosehnSo, if a script named
3548fbe7ebfSGarance A Drosehn.Pa /usr/local/bin/someport
3558fbe7ebfSGarance A Drosehnhad a first line of:
3568fbe7ebfSGarance A Drosehn.Pp
3575dea8a44SRuslan Ermilov.Dl "#!/usr/local/bin/php -n -q -dsafe_mode=0"
3588fbe7ebfSGarance A Drosehn.Pp
3598fbe7ebfSGarance A Drosehnthen the
3608fbe7ebfSGarance A Drosehn.Pa /usr/local/bin/php
3618fbe7ebfSGarance A Drosehnprogram would have been started with the arguments of:
3625dea8a44SRuslan Ermilov.Bd -literal -offset indent
3635dea8a44SRuslan Ermilovarg[0] = '/usr/local/bin/php'
3645dea8a44SRuslan Ermilovarg[1] = '-n'
3655dea8a44SRuslan Ermilovarg[2] = '-q'
3665dea8a44SRuslan Ermilovarg[3] = '-dsafe_mode=0'
3675dea8a44SRuslan Ermilovarg[4] = '/usr/local/bin/someport'
3685dea8a44SRuslan Ermilov.Ed
3698fbe7ebfSGarance A Drosehn.Pp
3705dea8a44SRuslan Ermilovplus any arguments the user specified when executing
3718fbe7ebfSGarance A Drosehn.Pa someport .
3728fbe7ebfSGarance A DrosehnHowever, this processing of multiple options on the
3738fbe7ebfSGarance A Drosehn.Ql #!
3748fbe7ebfSGarance A Drosehnline is not the way any other operating system parses the
3758fbe7ebfSGarance A Drosehnfirst line of an interpreted script.
3768fbe7ebfSGarance A DrosehnSo after a change which was made for
3778fbe7ebfSGarance A Drosehn.Fx 6.0
3788fbe7ebfSGarance A Drosehnrelease, that script will result in
3798fbe7ebfSGarance A Drosehn.Pa /usr/local/bin/php
3808fbe7ebfSGarance A Drosehnbeing started with the arguments of:
3815dea8a44SRuslan Ermilov.Bd -literal -offset indent
3825dea8a44SRuslan Ermilovarg[0] = '/usr/local/bin/php'
3835dea8a44SRuslan Ermilovarg[1] = '-n -q -dsafe_mode=0'
3845dea8a44SRuslan Ermilovarg[2] = '/usr/local/bin/someport'
3855dea8a44SRuslan Ermilov.Ed
3868fbe7ebfSGarance A Drosehn.Pp
3875dea8a44SRuslan Ermilovplus any arguments the user specified.
3888fbe7ebfSGarance A DrosehnThis caused a significant change in the behavior of a few scripts.
3898fbe7ebfSGarance A DrosehnIn the case of above script, to have it behave the same way under
3908fbe7ebfSGarance A Drosehn.Fx 6.0
3918fbe7ebfSGarance A Drosehnas it did under earlier releases, the first line should be
3928fbe7ebfSGarance A Drosehnchanged to:
3938fbe7ebfSGarance A Drosehn.Pp
3945dea8a44SRuslan Ermilov.Dl "#!/usr/bin/env -S /usr/local/bin/php -n -q -dsafe_mode=0"
39514f566d3STim J. Robbins.Pp
39614f566d3STim J. RobbinsThe
39752964a40SRuslan Ermilov.Nm
3988fbe7ebfSGarance A Drosehnutility will be started with the entire line as a single
3998fbe7ebfSGarance A Drosehnargument:
4008fbe7ebfSGarance A Drosehn.Pp
4015dea8a44SRuslan Ermilov.Dl "arg[1] = '-S /usr/local/bin/php -n -q -dsafe_mode=0'"
4028fbe7ebfSGarance A Drosehn.Pp
4038fbe7ebfSGarance A Drosehnand then
4048fbe7ebfSGarance A Drosehn.Fl S
4058fbe7ebfSGarance A Drosehnprocessing will split that line into separate arguments before
4068fbe7ebfSGarance A Drosehnexecuting
4078fbe7ebfSGarance A Drosehn.Pa /usr/local/bin/php .
4088fbe7ebfSGarance A Drosehn.\"
40914f566d3STim J. Robbins.Sh ENVIRONMENT
41014f566d3STim J. RobbinsThe
41152964a40SRuslan Ermilov.Nm
41214f566d3STim J. Robbinsutility uses the
41314f566d3STim J. Robbins.Ev PATH
414ec6001d9SJens Schweikhardtenvironment variable to locate the requested
41514f566d3STim J. Robbins.Ar utility
41614f566d3STim J. Robbinsif the name contains no
41714f566d3STim J. Robbins.Ql /
4188fbe7ebfSGarance A Drosehncharacters, unless the
4198fbe7ebfSGarance A Drosehn.Fl P
4205dea8a44SRuslan Ermilovoption has been specified.
421a866e170SRuslan Ermilov.Sh EXIT STATUS
42252964a40SRuslan Ermilov.Ex -std
423607e48e7SRuslan ErmilovAn exit status of 126 indicates that
42414f566d3STim J. Robbins.Ar utility
42514f566d3STim J. Robbinswas found, but could not be executed.
426607e48e7SRuslan ErmilovAn exit status of 127 indicates that
42714f566d3STim J. Robbins.Ar utility
42814f566d3STim J. Robbinscould not be found.
4298fbe7ebfSGarance A Drosehn.Sh EXAMPLES
4308fbe7ebfSGarance A DrosehnSince the
4318fbe7ebfSGarance A Drosehn.Nm
4328fbe7ebfSGarance A Drosehnutility is often used as part of the first line of an interpreted script,
4338fbe7ebfSGarance A Drosehnthe following examples show a number of ways that the
4348fbe7ebfSGarance A Drosehn.Nm
4358fbe7ebfSGarance A Drosehnutility can be useful in scripts.
4368fbe7ebfSGarance A Drosehn.Pp
4378fbe7ebfSGarance A DrosehnThe kernel processing of an interpreted script does not allow a script
4388fbe7ebfSGarance A Drosehnto directly reference some other script as its own interpreter.
4398fbe7ebfSGarance A DrosehnAs a way around this, the main difference between
4408fbe7ebfSGarance A Drosehn.Pp
4415dea8a44SRuslan Ermilov.Dl #!/usr/local/bin/foo
4428fbe7ebfSGarance A Drosehnand
4435dea8a44SRuslan Ermilov.Dl "#!/usr/bin/env /usr/local/bin/foo"
4448fbe7ebfSGarance A Drosehn.Pp
4458fbe7ebfSGarance A Drosehnis that the latter works even if
4468fbe7ebfSGarance A Drosehn.Pa /usr/local/bin/foo
4478fbe7ebfSGarance A Drosehnis itself an interpreted script.
4488fbe7ebfSGarance A Drosehn.Pp
4498fbe7ebfSGarance A DrosehnProbably the most common use of
4508fbe7ebfSGarance A Drosehn.Nm
4518fbe7ebfSGarance A Drosehnis to find the correct interpreter for a script, when the interpreter
4528fbe7ebfSGarance A Drosehnmay be in different directories on different systems.
4538fbe7ebfSGarance A DrosehnThe following example will find the
4548fbe7ebfSGarance A Drosehn.Ql perl
4555dea8a44SRuslan Ermilovinterpreter by searching through the directories specified by
4565dea8a44SRuslan Ermilov.Ev PATH .
4578fbe7ebfSGarance A Drosehn.Pp
4585dea8a44SRuslan Ermilov.Dl "#!/usr/bin/env perl"
4598fbe7ebfSGarance A Drosehn.Pp
4608fbe7ebfSGarance A DrosehnOne limitation of that example is that it assumes the user's value
4615dea8a44SRuslan Ermilovfor
4625dea8a44SRuslan Ermilov.Ev PATH
4635dea8a44SRuslan Ermilovis set to a value which will find the interpreter you want
4648fbe7ebfSGarance A Drosehnto execute.
4658fbe7ebfSGarance A DrosehnThe
4668fbe7ebfSGarance A Drosehn.Fl P
4675dea8a44SRuslan Ermilovoption can be used to make sure a specific list of directories is
4688fbe7ebfSGarance A Drosehnused in the search for
4698fbe7ebfSGarance A Drosehn.Ar utility .
4708fbe7ebfSGarance A DrosehnNote that the
4718fbe7ebfSGarance A Drosehn.Fl S
4728fbe7ebfSGarance A Drosehnoption is also required for this example to work correctly.
4738fbe7ebfSGarance A Drosehn.Pp
4745dea8a44SRuslan Ermilov.Dl "#!/usr/bin/env -S -P/usr/local/bin:/usr/bin perl"
4758fbe7ebfSGarance A Drosehn.Pp
4768fbe7ebfSGarance A DrosehnThe above finds
4778fbe7ebfSGarance A Drosehn.Ql perl
4788fbe7ebfSGarance A Drosehnonly if it is in
4798fbe7ebfSGarance A Drosehn.Pa /usr/local/bin
4808fbe7ebfSGarance A Drosehnor
4818fbe7ebfSGarance A Drosehn.Pa /usr/bin .
4825dea8a44SRuslan ErmilovThat could be combined with the present value of
4835dea8a44SRuslan Ermilov.Ev PATH ,
4845dea8a44SRuslan Ermilovto provide more flexibility.
4858fbe7ebfSGarance A DrosehnNote that spaces are not required between the
4868fbe7ebfSGarance A Drosehn.Fl S
4878fbe7ebfSGarance A Drosehnand
4888fbe7ebfSGarance A Drosehn.Fl P
4898fbe7ebfSGarance A Drosehnoptions:
4908fbe7ebfSGarance A Drosehn.Pp
4915dea8a44SRuslan Ermilov.Dl "#!/usr/bin/env -S-P/usr/local/bin:/usr/bin:${PATH} perl"
492a0dfb066SDag-Erling Smørgrav.Pp
493a0dfb066SDag-Erling SmørgravTo execute a utility with an equal sign in its name:
494a0dfb066SDag-Erling Smørgrav.Bd -literal -offset indent
495a0dfb066SDag-Erling Smørgravenv name=value ... command foo=bar arg ...
496a0dfb066SDag-Erling Smørgrav.Ed
49714f566d3STim J. Robbins.Sh COMPATIBILITY
49814f566d3STim J. RobbinsThe
49952964a40SRuslan Ermilov.Nm
50014f566d3STim J. Robbinsutility accepts the
50114f566d3STim J. Robbins.Fl
50214f566d3STim J. Robbinsoption as a synonym for
50314f566d3STim J. Robbins.Fl i .
50414f566d3STim J. Robbins.Sh SEE ALSO
50514f566d3STim J. Robbins.Xr printenv 1 ,
50614f566d3STim J. Robbins.Xr sh 1 ,
50714f566d3STim J. Robbins.Xr execvp 3 ,
50885c8521eSKyle Evans.Xr login.conf 5 ,
50914f566d3STim J. Robbins.Xr environ 7
51014f566d3STim J. Robbins.Sh STANDARDS
51114f566d3STim J. RobbinsThe
51252964a40SRuslan Ermilov.Nm
51314f566d3STim J. Robbinsutility conforms to
51414f566d3STim J. Robbins.St -p1003.1-2001 .
5158fbe7ebfSGarance A DrosehnThe
516*6f6166e4SDag-Erling Smørgrav.Fl 0 , C , L , P , S , U , u
5178fbe7ebfSGarance A Drosehnand
5188fbe7ebfSGarance A Drosehn.Fl v
519a414225dSGarance A Drosehnoptions are non-standard extensions supported by
520a414225dSGarance A Drosehn.Fx ,
521a414225dSGarance A Drosehnbut which may not be available on other operating systems.
5228fbe7ebfSGarance A Drosehn.Sh HISTORY
5238fbe7ebfSGarance A DrosehnThe
5248fbe7ebfSGarance A Drosehn.Nm
5258fbe7ebfSGarance A Drosehncommand appeared in
5268fbe7ebfSGarance A Drosehn.Bx 4.4 .
5278fbe7ebfSGarance A DrosehnThe
5288fbe7ebfSGarance A Drosehn.Fl P , S
5298fbe7ebfSGarance A Drosehnand
5308fbe7ebfSGarance A Drosehn.Fl v
5318fbe7ebfSGarance A Drosehnoptions were added in
5328fbe7ebfSGarance A Drosehn.Fx 6.0 .
53385c8521eSKyle EvansThe
53485c8521eSKyle Evans.Fl 0 , L
53585c8521eSKyle Evansand
53685c8521eSKyle Evans.Fl U
53785c8521eSKyle Evansoptions were added in
53885c8521eSKyle Evans.Fx 13.0 .
539*6f6166e4SDag-Erling SmørgravThe
540*6f6166e4SDag-Erling Smørgrav.Fl C
541*6f6166e4SDag-Erling Smørgravoption was added in
542*6f6166e4SDag-Erling Smørgrav.Fx 14.2 .
54314f566d3STim J. Robbins.Sh BUGS
54414f566d3STim J. RobbinsThe
54552964a40SRuslan Ermilov.Nm
5468fbe7ebfSGarance A Drosehnutility does not take multibyte characters into account when
5478fbe7ebfSGarance A Drosehnprocessing the
5488fbe7ebfSGarance A Drosehn.Fl S
5498fbe7ebfSGarance A Drosehnoption, which may lead to incorrect results in some locales.
550