The env utility shall obtain the current environment, modify it according
to its arguments, then invoke the utility named by the utility operand
with the modified environment.
Optional arguments shall be passed to utility.
If no utility operand is specified, the resulting environment shall be
written to the standard output, with one name= value pair per
The following environment variables shall affect the execution of env:
Provide a default value for the internationalization
variables that are unset or null. (See the Base Definitions volume of
IEEE Std 1003.1-2001, Section 8.2, Internationalization
Variables for the precedence of internationalization variables used to
determine the values of locale categories.)
If set to a non-empty string value, override the values of
all the other internationalization variables.
Determine the locale for the interpretation of sequences of
bytes of text data as characters (for example, single-byte as opposed to
multi-byte characters in arguments).
Determine the locale that should be used to affect the
format and contents of diagnostic messages written to standard error.
Determine the location of message catalogs for the
processing of LC_MESSAGES.
Determine the location of the utility, as described
in the Base Definitions volume of IEEE Std 1003.1-2001,
Chapter 8, Environment Variables. If PATH is specified as a
name= value operand to env, the value given
shall be used in the search for utility.
The command, env, nice, nohup, time, and
xargs utilities have been specified to use exit code 127 if an error
occurs so that applications can distinguish "failure to find a
utility" from "invoked utility exited with an error
indication". The value 127 was chosen because it is not commonly used for
other meanings; most utilities use small values for "normal error
conditions" and the values above 128 can be confused with termination due
to receipt of a signal. The value 126 was chosen in a similar manner to
indicate that the utility could be found, but not invoked. Some scripts
produce meaningful error messages differentiating the 126 and 127 cases. The
distinction between exit codes 126 and 127 is based on KornShell practice that
uses 127 when all attempts to exec the utility fail with [ENOENT], and
uses 126 when any attempt to exec the utility fails for any other
Historical implementations of the env utility use the execvp() or
execlp() functions defined in the System Interfaces volume of
IEEE Std 1003.1-2001 to invoke the specified utility; this
provides better performance and keeps users from having to escape characters
with special meaning to the shell. Therefore, shell functions, special
built-ins, and built-ins that are only provided by the shell are not found.
As with all other utilities that invoke other utilities, this volume of
IEEE Std 1003.1-2001 only specifies what env does with
standard input, standard output, standard error, input files, and output
files. If a utility is executed, it is not constrained by the specification of
input and output by env.
The -i option was added to allow the functionality of the withdrawn
- option in a manner compatible with the Utility Syntax Guidelines.
Some have suggested that env is redundant since the same effect is
name=value ... utility[argument ...]
The example is equivalent to env when an environment variable is being
added to the environment of the command, but not when the environment is being
set to the given value. The env utility also writes out the current
environment if invoked without arguments. There is sufficient functionality
beyond what the example provides to justify inclusion of env.
Portions of this text are reprinted and reproduced in electronic form from IEEE
Std 1003.1, 2003 Edition, Standard for Information Technology -- Portable
Operating System Interface (POSIX), The Open Group Base Specifications Issue
6, Copyright (C) 2001-2003 by the Institute of Electrical and Electronics
Engineers, Inc and The Open Group. In the event of any discrepancy between
this version and the original IEEE and The Open Group Standard, the original
IEEE and The Open Group Standard is the referee document. The original
Standard can be obtained online at http://www.opengroup.org/unix/online.html