ENV(1) | General Commands Manual | ENV(1) |
env
— set and
print environment
env |
[-0i ] [-C
dir] [-u
name]
[- - ]
[name=value ...]
[- - ]
[utility [argument ...]] |
env
executes
utility, with the given
arguments, after modifying the environment as
specified on the command line. Each name=value option
specifies an environment variable, name, with a value
of value which may be empty, that is to replace an
existing environment variable with the same name, or
otherwise is to be added to the environment.
The ‘-i
’ option causes
env
to completely ignore the environment it
inherits.
The ‘-C
dir’ option causes the working directory to be
changed to dir, and the environment variable
PWD
to be removed from the environment.
The ‘-u
name’ option causes removal of the
name environment variable if it is in the environment.
This is similar to the unset
command in
sh(1). The value for
name must not include the
‘=
’ character.
To allow for either a name to be added to
the environment, or the utility's name (if no
environment additions are present), to begin with a minus sign
(‘-’) the first
“-
-
” argument
is required. To allow for utility's name to contain an
equals character (‘=’) (anywhere in its word) the second
“-
-
” is
required. If there are no name=value arguments given,
then to allow for utility to contain an equals
character, both
“-
-
” arguments
are required. The first ends the options, the second ends the (in this case
empty) environment variable additions.
If no utility is specified,
env
prints out the names and values of the variables
in the environment. Each name=value pair is separated
by a new line unless -0
is specified, in which case
name/value pairs are separated by a nul character (‘\0’). The
-0
option is ignored if a
utility is given.
If a utility is specified, can be located,
and successfully invoked, the exit status of env
is
the exit status of the utility. See its documentation
for the possible values and interpretations.
Otherwise env
exits with one of the
following values:
env
has successfully written the contents of the
(possibly modified) environment to standard output.env
was given an invalid option, a requested
operation failed, or some other error occurred.Whenever env
exits with a non-zero status,
without having invoked a utility, it writes a message
to the standard error stream identifying itself, and the reason for the
non-zero exit. This can help distinguish cases where
env
exits because of a problem, from when
utility does so. The case of a zero exit status is
simpler; if a utility was given on the command line,
the zero status is from that utility, otherwise it is from
env
.
The historic -
option has been deprecated
but is still supported in this implementation.
The -C
, -u
and
-0
options are non-standard extensions.
The env
utility conforms to
IEEE Std 1003.2-1992 (“POSIX.2”).
The env
command appeared in
4.4BSD.
The -u
and -0
options first appeared in NetBSD 10, after earlier
appearing in other systems.
The -C
option first appeared in
NetBSD 10.1.
February 9, 2025 | NetBSD 10.99 |