1ENV(1P)                    POSIX Programmer's Manual                   ENV(1P)
2
3
4

PROLOG

6       This  manual  page is part of the POSIX Programmer's Manual.  The Linux
7       implementation of this interface may differ (consult the  corresponding
8       Linux  manual page for details of Linux behavior), or the interface may
9       not be implemented on Linux.
10
11

NAME

13       env — set the environment for command invocation
14

SYNOPSIS

16       env [−i] [name=value]... [utility [argument...]]
17

DESCRIPTION

19       The env utility shall obtain the current environment, modify it accord‐
20       ing  to its arguments, then invoke the utility named by the utility op‐
21       erand with the modified environment.
22
23       Optional arguments shall be passed to utility.
24
25       If no utility operand is specified, the resulting environment shall  be
26       written to the standard output, with one name=value pair per line.
27
28       If the first argument is '−', the results are unspecified.
29

OPTIONS

31       The  env  utility  shall  conform  to  the  Base  Definitions volume of
32       POSIX.1‐2008, Section 12.2, Utility Syntax Guidelines, except  for  the
33       unspecified usage of '−'.
34
35       The following options shall be supported:
36
37       −i        Invoke  utility with exactly the environment specified by the
38                 arguments; the inherited environment shall  be  ignored  com‐
39                 pletely.
40

OPERANDS

42       The following operands shall be supported:
43
44       name=value
45                 Arguments  of  the form name=value shall modify the execution
46                 environment, and shall be placed into the inherited  environ‐
47                 ment before the utility is invoked.
48
49       utility   The name of the utility to be invoked. If the utility operand
50                 names any of the special built-in utilities in Section  2.14,
51                 Special Built-In Utilities, the results are undefined.
52
53       argument  A string to pass as an argument for the invoked utility.
54

STDIN

56       Not used.
57

INPUT FILES

59       None.
60

ENVIRONMENT VARIABLES

62       The following environment variables shall affect the execution of env:
63
64       LANG      Provide  a  default  value for the internationalization vari‐
65                 ables that are unset or null. (See the Base Definitions  vol‐
66                 ume  of POSIX.1‐2008, Section 8.2, Internationalization Vari‐
67                 ables for the precedence  of  internationalization  variables
68                 used to determine the values of locale categories.)
69
70       LC_ALL    If  set  to  a non-empty string value, override the values of
71                 all the other internationalization variables.
72
73       LC_CTYPE  Determine the locale for the interpretation of  sequences  of
74                 bytes of text data as characters (for example, single-byte as
75                 opposed to multi-byte characters in arguments).
76
77       LC_MESSAGES
78                 Determine the locale that should be used to affect the format
79                 and  contents  of  diagnostic  messages  written  to standard
80                 error.
81
82       NLSPATH   Determine the location of message catalogs for the processing
83                 of LC_MESSAGES.
84
85       PATH      Determine  the  location  of the utility, as described in the
86                 Base Definitions volume of POSIX.1‐2008, Chapter 8,  Environ‐
87                 ment Variables.  If PATH is specified as a name=value operand
88                 to env, the value given shall be used in the search for util‐
89                 ity.
90

ASYNCHRONOUS EVENTS

92       Default.
93

STDOUT

95       If no utility operand is specified, each name=value pair in the result‐
96       ing environment shall be written in the form:
97
98           "%s=%s\n", <name>, <value>
99
100       If the utility operand is specified, the env utility shall not write to
101       standard output.
102

STDERR

104       The standard error shall be used only for diagnostic messages.
105

OUTPUT FILES

107       None.
108

EXTENDED DESCRIPTION

110       None.
111

EXIT STATUS

113       If  utility is invoked, the exit status of env shall be the exit status
114       of utility; otherwise, the env utility shall exit with one of the  fol‐
115       lowing values:
116
117           0   The env utility completed successfully.
118
119       1−125   An error occurred in the env utility.
120
121         126   The  utility  specified  by  utility was found but could not be
122               invoked.
123
124         127   The utility specified by utility could not be found.
125

CONSEQUENCES OF ERRORS

127       Default.
128
129       The following sections are informative.
130

APPLICATION USAGE

132       The command, env, nice, nohup, time,  and  xargs  utilities  have  been
133       specified  to use exit code 127 if an error occurs so that applications
134       can distinguish ``failure to find a utility''  from  ``invoked  utility
135       exited  with an error indication''. The value 127 was chosen because it
136       is not commonly used for other meanings; most utilities use small  val‐
137       ues  for  ``normal  error  conditions'' and the values above 128 can be
138       confused with termination due to receipt of a signal. The value 126 was
139       chosen in a similar manner to indicate that the utility could be found,
140       but not invoked. Some scripts produce meaningful error messages differ‐
141       entiating the 126 and 127 cases. The distinction between exit codes 126
142       and 127 is based on KornShell practice that uses 127 when all  attempts
143       to  exec  the utility fail with [ENOENT], and uses 126 when any attempt
144       to exec the utility fails for any other reason.
145
146       Historical implementations of the env utility use the execvp() or  exe‐
147       clp() functions defined in the System Interfaces volume of POSIX.1‐2008
148       to invoke the specified utility; this provides better  performance  and
149       keeps  users  from  having to escape characters with special meaning to
150       the shell. Therefore, shell functions, special built-ins, and built-ins
151       that are only provided by the shell are not found.
152

EXAMPLES

154       The following command:
155
156           env −i PATH=/mybin:"$PATH" $(getconf V7_ENV) mygrep xyz myfile
157
158       invokes  the  command mygrep with a new PATH value as the only entry in
159       its environment other than any variables required by the implementation
160       for  conformance. In this case, PATH is used to locate mygrep, which is
161       expected to reside in /mybin.
162

RATIONALE

164       As with all other utilities that invoke other utilities, this volume of
165       POSIX.1‐2008 only specifies what env does with standard input, standard
166       output, standard error, input files, and output files. If a utility  is
167       executed,  it is not constrained by the specification of input and out‐
168       put by env.
169
170       The −i option was added to allow the functionality  of  the  removed  
171       option in a manner compatible with the Utility Syntax Guidelines. It is
172       possible to create a non-conforming environment using the −i option, as
173       it  may remove environment variables required by the implementation for
174       conformance. The following will preserve these environment variables as
175       well as preserve the PATH for conforming utilities:
176
177           IFS='
178           '
179           # The preceding value should be <space><tab><newline>.
180           # Set IFS to its default value.
181
182           set −f
183           # disable pathname expansion
184
185           \unalias −a
186           # Unset all possible aliases.
187           # Note that unalias is escaped to prevent an alias
188           # being used for unalias.
189           # This step is not strictly necessary, since aliases are not inherited,
190           # and the ENV environment variable is only used by interactive shells,
191           # the only way any aliases can exist in a script is if it defines them
192           # itself.
193
194           unset −f env getconf
195           # Ensure env and getconf are not user functions.
196
197           env −i $(getconf V7_ENV) PATH="$(getconf PATH)" command
198
199       Some  have  suggested  that  env  is redundant since the same effect is
200       achieved by:
201
202           name=value ... utility [ argument ... ]
203
204       The example is equivalent to env when an environment variable is  being
205       added  to  the environment of the command, but not when the environment
206       is being set to the given value.  The env utility also writes  out  the
207       current  environment  if invoked without arguments. There is sufficient
208       functionality beyond what the example provides to justify inclusion  of
209       env.
210

FUTURE DIRECTIONS

212       None.
213

SEE ALSO

215       Section  2.14,  Special Built-In Utilities, Section 2.5, Parameters and
216       Variables
217
218       The Base Definitions volume of  POSIX.1‐2008,  Chapter  8,  Environment
219       Variables, Section 12.2, Utility Syntax Guidelines
220
222       Portions  of  this text are reprinted and reproduced in electronic form
223       from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
224       --  Portable  Operating  System  Interface (POSIX), The Open Group Base
225       Specifications Issue 7, Copyright (C) 2013 by the Institute of Electri‐
226       cal  and  Electronics  Engineers,  Inc  and  The  Open Group.  (This is
227       POSIX.1-2008 with the 2013 Technical Corrigendum  1  applied.)  In  the
228       event of any discrepancy between this version and the original IEEE and
229       The Open Group Standard, the original IEEE and The Open Group  Standard
230       is  the  referee document. The original Standard can be obtained online
231       at http://www.unix.org/online.html .
232
233       Any typographical or formatting errors that appear  in  this  page  are
234       most likely to have been introduced during the conversion of the source
235       files to man page format. To report such errors,  see  https://www.ker
236       nel.org/doc/man-pages/reporting_bugs.html .
237
238
239
240IEEE/The Open Group                  2013                              ENV(1P)
Impressum