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

NAME

12       env - set the environment for command invocation
13

SYNOPSIS

15       env [-i][name=value]...  [utility [argument...]]
16

DESCRIPTION

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

OPTIONS

28       The  env  utility  shall  conform  to  the  Base  Definitions volume of
29       IEEE Std 1003.1-2001, Section 12.2, Utility Syntax Guidelines.
30
31       The following options shall be supported:
32
33       -i     Invoke utility with exactly the  environment  specified  by  the
34              arguments;  the  inherited  environment  shall  be  ignored com‐
35              pletely.
36
37

OPERANDS

39       The following operands shall be supported:
40
41       name=value
42              Arguments of the form name= value  shall  modify  the  execution
43              environment,  and shall be placed into the inherited environment
44              before the utility is invoked.
45
46       utility
47              The name of the utility to be invoked. If  the  utility  operand
48              names  any of the special built-in utilities in Special Built-In
49              Utilities, the results are undefined.
50
51       argument
52              A string to pass as an argument for the invoked utility.
53
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  variables
65              that  are  unset  or  null.  (See the Base Definitions volume of
66              IEEE Std 1003.1-2001, Section  8.2,  Internationalization  Vari‐
67              ables  for the precedence of internationalization variables used
68              to determine the values of locale categories.)
69
70       LC_ALL If set to a non-empty string value, override the values  of  all
71              the other internationalization variables.
72
73       LC_CTYPE
74              Determine  the  locale  for  the  interpretation of sequences of
75              bytes of text data as characters (for  example,  single-byte  as
76              opposed to multi-byte characters in arguments).
77
78       LC_MESSAGES
79              Determine  the  locale  that should be used to affect the format
80              and contents of diagnostic messages written to standard error.
81
82       NLSPATH
83              Determine the location of message catalogs for the processing of
84              LC_MESSAGES .
85
86       PATH   Determine  the location of the utility, as described in the Base
87              Definitions volume of IEEE Std 1003.1-2001, Chapter 8,  Environ‐
88              ment Variables. If PATH is specified as a name= value operand to
89              env, the value given shall be used in the search for utility.
90
91

ASYNCHRONOUS EVENTS

93       Default.
94

STDOUT

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

STDERR

106       The standard error shall be used only for diagnostic messages.
107

OUTPUT FILES

109       None.
110

EXTENDED DESCRIPTION

112       None.
113

EXIT STATUS

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

CONSEQUENCES OF ERRORS

130       Default.
131
132       The following sections are informative.
133

APPLICATION USAGE

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

EXAMPLES

158       The following command:
159
160
161              env -i PATH=/mybin mygrep xyz myfile
162
163       invokes  the  command mygrep with a new PATH value as the only entry in
164       its environment. In this case, PATH is used  to  locate  mygrep,  which
165       then must reside in /mybin.
166

RATIONALE

168       As with all other utilities that invoke other utilities, this volume of
169       IEEE Std 1003.1-2001 only specifies what env does with standard  input,
170       standard  output,  standard  error, input files, and output files. If a
171       utility is executed, it is not  constrained  by  the  specification  of
172       input and output by env.
173
174       The  -i  option was added to allow the functionality of the withdrawn -
175       option in a manner compatible with the Utility Syntax Guidelines.
176
177       Some have suggested that env is redundant  since  the  same  effect  is
178       achieved by:
179
180
181              name=value ... utility [ argument ... ]
182
183       The  example is equivalent to env when an environment variable is being
184       added to the environment of the command, but not when  the  environment
185       is  being  set  to the given value. The env utility also writes out the
186       current environment if invoked without arguments. There  is  sufficient
187       functionality  beyond what the example provides to justify inclusion of
188       env.
189

FUTURE DIRECTIONS

191       None.
192

SEE ALSO

194       Parameters and Variables, Special Built-In Utilities
195
197       Portions of this text are reprinted and reproduced in  electronic  form
198       from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
199       -- Portable Operating System Interface (POSIX),  The  Open  Group  Base
200       Specifications  Issue  6,  Copyright  (C) 2001-2003 by the Institute of
201       Electrical and Electronics Engineers, Inc and The Open  Group.  In  the
202       event of any discrepancy between this version and the original IEEE and
203       The Open Group Standard, the original IEEE and The Open Group  Standard
204       is  the  referee document. The original Standard can be obtained online
205       at http://www.opengroup.org/unix/online.html .
206
207
208
209IEEE/The Open Group                  2003                              ENV(1P)
Impressum