Section: POSIX Programmer's Manual (1P)
This manual page is part of the POSIX Programmer's Manual.
The Linux implementation of this interface may differ (consult
the corresponding Linux manual page for details of Linux behavior),
or the interface may not be implemented on Linux.
--- set the environment for command invocation
env [-i] [name=value]... [utility [argument...]]
utility shall obtain the current environment, modify it according to
its arguments, then invoke the utility named by the
operand with the modified environment.
Optional arguments shall be passed to
operand is specified, the resulting environment shall be written to the
standard output, with one
pair per line.
If the first argument is
the results are unspecified.
utility shall conform to the Base Definitions volume of POSIX.1-2008,
, Utility Syntax Guidelines,
except for the unspecified usage of
The following options shall be supported:
with exactly the environment specified by the arguments; the inherited
environment shall be ignored completely.
The following operands shall be supported:
Arguments of the form
shall modify the execution environment, and shall be placed into the
inherited environment before the
The name of the utility to be invoked. If the
operand names any of the special built-in utilities in
Section 2.14, Special Built-In Utilities,
the results are undefined.
A string to pass as an argument for the invoked utility.
The following environment variables shall affect the execution of
Provide a default value for the internationalization variables that are
unset or null. (See the Base Definitions volume of POSIX.1-2008,
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
Determine the location of the
as described in the Base Definitions volume of POSIX.1-2008,
Chapter 8, Environment Variables.
is specified as a
given shall be used in the search for
operand is specified, each
pair in the resulting environment shall be written in the form:
"%s=%s\n", <name>, <value>
operand is specified, the
utility shall not write to standard output.
The standard error shall be used only for diagnostic messages.
is invoked, the exit status of
shall be the exit status of
utility shall exit with one of the following values:
utility completed successfully.
An error occurred in the
The utility specified by
was found but could not be invoked.
The utility specified by
could not be found.
CONSEQUENCES OF ERRORS
The following sections are informative.
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
the utility fail with
and uses 126 when any attempt to
the utility fails for any other reason.
Historical implementations of the
utility use the
functions defined in the System Interfaces volume of POSIX.1-2008 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.
The following command:
env -i PATH=/mybin:"$PATH" $(getconf V7_ENV) mygrep xyz myfile
invokes the command
with a new
value as the only entry in its environment other than any variables
required by the implementation for conformance. In this case,
is used to locate
which is expected to reside in
As with all other utilities that invoke other utilities, this volume of POSIX.1-2008 only
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
option was added to allow the functionality of the removed
option in a manner compatible with the Utility Syntax Guidelines. It
is possible to create a non-conforming environment using the
option, as it may remove environment variables required by the
implementation for conformance. The following will preserve these
environment variables as well as preserve the
for conforming utilities:
# The preceding value should be <space><tab><newline>.
# Set IFS to its default value.
# disable pathname expansion
# Unset all possible aliases.
# Note that unalias is escaped to prevent an alias
# being used for unalias.
# This step is not strictly necessary, since aliases are not inherited,
# and the ENV environment variable is only used by interactive shells,
# the only way any aliases can exist in a script is if it defines them
unset -f env getconf
# Ensure env and getconf are not user functions.
env -i $(getconf V7_ENV) PATH="$(getconf PATH)" command
Some have suggested that
is redundant since the same effect is achieved by:
name=value ... utility [ argument ... ]
The example is equivalent to
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.
utility also writes out the current environment if invoked without
arguments. There is sufficient functionality beyond what the example
provides to justify inclusion of
, Special Built-In Utilities,
, Parameters and Variables
The Base Definitions volume of POSIX.1-2008,
Chapter 8, Environment Variables,
Section 12.2, Utility Syntax Guidelines
Portions of this text are reprinted and reproduced in electronic form
from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
-- Portable Operating System Interface (POSIX), The Open Group Base
Specifications Issue 7, Copyright (C) 2013 by the Institute of
Electrical and Electronics Engineers, Inc and The Open Group.
(This is POSIX.1-2008 with the 2013 Technical Corrigendum 1 applied.) 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
Any typographical or formatting errors that appear
in this page are most likely
to have been introduced during the conversion of the source files to
man page format. To report such errors, see