1ENV(P) POSIX Programmer's Manual ENV(P)
2
3
4
6 env - set the environment for command invocation
7
9 env [-i][name=value]... [utility [argument...]]
10
12 The env utility shall obtain the current environment, modify it accord‐
13 ing to its arguments, then invoke the utility named by the utility op‐
14 erand with the modified environment.
15
16 Optional arguments shall be passed to utility.
17
18 If no utility operand is specified, the resulting environment shall be
19 written to the standard output, with one name= value pair per line.
20
22 The env utility shall conform to the Base Definitions volume of
23 IEEE Std 1003.1-2001, Section 12.2, Utility Syntax Guidelines.
24
25 The following options shall be supported:
26
27 -i Invoke utility with exactly the environment specified by the
28 arguments; the inherited environment shall be ignored com‐
29 pletely.
30
31
33 The following operands shall be supported:
34
35 name=value
36 Arguments of the form name= value shall modify the execution
37 environment, and shall be placed into the inherited environment
38 before the utility is invoked.
39
40 utility
41 The name of the utility to be invoked. If the utility operand
42 names any of the special built-in utilities in Special Built-In
43 Utilities , the results are undefined.
44
45 argument
46 A string to pass as an argument for the invoked utility.
47
48
50 Not used.
51
53 None.
54
56 The following environment variables shall affect the execution of env:
57
58 LANG Provide a default value for the internationalization variables
59 that are unset or null. (See the Base Definitions volume of
60 IEEE Std 1003.1-2001, Section 8.2, Internationalization Vari‐
61 ables for the precedence of internationalization variables used
62 to determine the values of locale categories.)
63
64 LC_ALL If set to a non-empty string value, override the values of all
65 the other internationalization variables.
66
67 LC_CTYPE
68 Determine the locale for the interpretation of sequences of
69 bytes of text data as characters (for example, single-byte as
70 opposed to multi-byte characters in arguments).
71
72 LC_MESSAGES
73 Determine the locale that should be used to affect the format
74 and contents of diagnostic messages written to standard error.
75
76 NLSPATH
77 Determine the location of message catalogs for the processing of
78 LC_MESSAGES .
79
80 PATH Determine the location of the utility, as described in the Base
81 Definitions volume of IEEE Std 1003.1-2001, Chapter 8, Environ‐
82 ment Variables. If PATH is specified as a name= value operand to
83 env, the value given shall be used in the search for utility.
84
85
87 Default.
88
90 If no utility operand is specified, each name= value pair in the
91 resulting environment shall be written in the form:
92
93
94 "%s=%s\n", <name>, <value>
95
96 If the utility operand is specified, the env utility shall not write to
97 standard output.
98
100 The standard error shall be used only for diagnostic messages.
101
103 None.
104
106 None.
107
109 If utility is invoked, the exit status of env shall be the exit status
110 of utility; otherwise, the env utility shall exit with one of the fol‐
111 lowing values:
112
113 0 The env utility completed successfully.
114
115 1-125 An error occurred in the env utility.
116
117 126 The utility specified by utility was found but could not be
118 invoked.
119
120 127 The utility specified by utility could not be found.
121
122
124 Default.
125
126 The following sections are informative.
127
129 The command, env, nice, nohup, time, and xargs utilities have been
130 specified to use exit code 127 if an error occurs so that applications
131 can distinguish "failure to find a utility" from "invoked utility
132 exited with an error indication". The value 127 was chosen because it
133 is not commonly used for other meanings; most utilities use small val‐
134 ues for "normal error conditions" and the values above 128 can be con‐
135 fused with termination due to receipt of a signal. The value 126 was
136 chosen in a similar manner to indicate that the utility could be found,
137 but not invoked. Some scripts produce meaningful error messages differ‐
138 entiating the 126 and 127 cases. The distinction between exit codes 126
139 and 127 is based on KornShell practice that uses 127 when all attempts
140 to exec the utility fail with [ENOENT], and uses 126 when any attempt
141 to exec the utility fails for any other reason.
142
143 Historical implementations of the env utility use the execvp() or exe‐
144 clp() functions defined in the System Interfaces volume of
145 IEEE Std 1003.1-2001 to invoke the specified utility; this provides
146 better performance and keeps users from having to escape characters
147 with special meaning to the shell. Therefore, shell functions, special
148 built-ins, and built-ins that are only provided by the shell are not
149 found.
150
152 The following command:
153
154
155 env -i PATH=/mybin mygrep xyz myfile
156
157 invokes the command mygrep with a new PATH value as the only entry in
158 its environment. In this case, PATH is used to locate mygrep, which
159 then must reside in /mybin.
160
162 As with all other utilities that invoke other utilities, this volume of
163 IEEE Std 1003.1-2001 only specifies what env does with standard input,
164 standard output, standard error, input files, and output files. If a
165 utility is executed, it is not constrained by the specification of
166 input and output by env.
167
168 The -i option was added to allow the functionality of the withdrawn -
169 option in a manner compatible with the Utility Syntax Guidelines.
170
171 Some have suggested that env is redundant since the same effect is
172 achieved by:
173
174
175 name=value ... utility [ argument ... ]
176
177 The example is equivalent to env when an environment variable is being
178 added to the environment of the command, but not when the environment
179 is being set to the given value. The env utility also writes out the
180 current environment if invoked without arguments. There is sufficient
181 functionality beyond what the example provides to justify inclusion of
182 env.
183
185 None.
186
188 Parameters and Variables , Special Built-In Utilities
189
191 Portions of this text are reprinted and reproduced in electronic form
192 from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
193 -- Portable Operating System Interface (POSIX), The Open Group Base
194 Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of
195 Electrical and Electronics Engineers, Inc and The Open Group. In the
196 event of any discrepancy between this version and the original IEEE and
197 The Open Group Standard, the original IEEE and The Open Group Standard
198 is the referee document. The original Standard can be obtained online
199 at http://www.opengroup.org/unix/online.html .
200
201
202
203IEEE/The Open Group 2003 ENV(P)