xref: /netbsd-src/usr.bin/env/env.1 (revision b4519c5b39ea2ac24cca20cbfc9f67a6716dcc78)
1.\"	$NetBSD: env.1,v 1.16 2024/10/28 11:30:37 kim Exp $
2.\"
3.\" Copyright (c) 1980, 1990 The Regents of the University of California.
4.\" All rights reserved.
5.\"
6.\" This code is derived from software contributed to Berkeley by
7.\" the Institute of Electrical and Electronics Engineers, Inc.
8.\" Redistribution and use in source and binary forms, with or without
9.\" modification, are permitted provided that the following conditions
10.\" are met:
11.\" 1. Redistributions of source code must retain the above copyright
12.\"    notice, this list of conditions and the following disclaimer.
13.\" 2. Redistributions in binary form must reproduce the above copyright
14.\"    notice, this list of conditions and the following disclaimer in the
15.\"    documentation and/or other materials provided with the distribution.
16.\" 3. Neither the name of the University nor the names of its contributors
17.\"    may be used to endorse or promote products derived from this software
18.\"    without specific prior written permission.
19.\"
20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30.\" SUCH DAMAGE.
31.\"
32.\"	from: @(#)printenv.1	6.7 (Berkeley) 7/28/91
33.\"	$NetBSD: env.1,v 1.16 2024/10/28 11:30:37 kim Exp $
34.\"
35.Dd October 28, 2024
36.Dt ENV 1
37.Os
38.Sh NAME
39.Nm env
40.Nd set and print environment
41.Sh SYNOPSIS
42.Nm
43.Op Fl 0i
44.Op Fl C Ar dir
45.Op Fl u Ar name
46.Op Ar name=value ...
47.Oo
48.Ar utility
49.Op argument ...
50.Oc
51.Sh DESCRIPTION
52.Nm
53executes
54.Ar utility
55after modifying the environment as
56specified on the command line.
57Each
58.Ar name=value
59option specifies
60an environmental variable,
61.Ar name  ,
62with a value of
63.Ar value  .
64The
65.Sq Fl i
66option causes
67.Nm
68to completely ignore the environment
69it inherits.
70.Pp
71The
72.Sq Fl C Ar dir
73option causes the working directory to be changed to
74.Ar dir .
75.Pp
76The
77.Sq Fl u Ar name
78option causes removal of the
79.Ar name
80environment variable if it is in the environment.
81This is similar to the
82.Ic unset
83command in
84.Xr sh 1 .
85The value for
86.Ar name
87must not include the
88.Ql =
89character.
90.Pp
91If no
92.Ar utility
93is specified,
94.Nm
95prints out the names and values of the variables in the environment.
96Each
97.Ar name=value
98pair is separated by a new line unless
99.Fl 0
100is specified, in which case name/value pairs are separated by NUL.
101The
102.Fl 0
103option and
104.Ar utility
105must not be specified together.
106.Sh EXIT STATUS
107.Nm
108exits with one of the following values:
109.Bl -tag -width Ds
110.It 0
111.Ar utility
112was invoked and completed successfully.
113In this case the exit code is returned by the utility itself, not
114.Nm .
115If no utility was specified, then
116.Nm
117completed successfully and returned the exit code itself.
118.It 1
119An invalid command line option was passed to
120.Nm .
121.It 1\-125
122.Ar utility
123was invoked, but failed in some way;
124see its manual page for more information.
125In this case the exit code is returned by the utility itself, not
126.Nm .
127.It 125
128.Ar utility
129was specified together with the
130.Fl 0
131option.
132.It 126
133.Ar utility
134was found, but could not be invoked.
135.It 127
136.Ar utility
137could not be found.
138.El
139.Sh COMPATIBILITY
140The historic
141.Fl
142option has been deprecated but is still supported in this implementation.
143.Pp
144The
145.Fl C , u
146and
147.Fl 0
148options are non-standard extensions.
149.Sh SEE ALSO
150.Xr chdir 2 ,
151.Xr execvp 3 ,
152.Xr environ 7
153.Sh STANDARDS
154The
155.Nm
156utility conforms to
157.St -p1003.2-92 .
158.Sh HISTORY
159The
160.Nm
161command appeared in
162.Bx 4.4 .
163.Pp
164The
165.Fl u
166and
167.Fl 0
168options first appeared in
169.Nx 10 .
170.Pp
171The
172.Fl C
173option first appeared in
174.Nx 10.1 .
175.Sh BUGS
176.Nm
177doesn't handle commands with equal
178.Pq Dq =
179signs in their
180names, for obvious reasons.
181