ENV(1P)
ENV(1P) ๐
okay bestie, gather round, because this is the POSIX Programmer's Manual page for env, and she is honestly kind of iconic. ๐
PROLOG โจ
So, real talk: this manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ โ like, pls consult the corresponding Linux manual page for deets on Linux behavior โ or honestly the interface may not even be implemented on Linux at all. ๐
NAME ๐
env โ set the environment for command invocation. she sets the vibe (the environment) before your command walks in. periodt.
SYNOPSIS ๐ธ
env [-i] [name=value]... [utility [argument...]]
DESCRIPTION ๐
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. like she grabs the environment, gives it a lil glow-up based on what you told her, and then hands it to your command. ๐ซถ
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 line. so if you don't give her a command to run, she just prints the whole environment at you. no cap.
If the first argument is '-', the results are unspecified. โ ๏ธ (translation: don't do that, bestie, nobody knows what happens.)
OPTIONS ๐
The env utility shall conform to the Base Definitions volume of POSIX.1โ2017, Section 12.2, Utility Syntax Guidelines, except for the unspecified usage of '-'.
The following options shall be supported:
-iโ Invoke utility with exactly the environment specified by the arguments; the inherited environment shall be ignored completely. she wipes the slate CLEAN, like a factory reset but for your environment. ๐
OPERANDS ๐ฆ
The following operands shall be supported:
name=valueโ Arguments of the formname=valueshall modify the execution environment, and shall be placed into the inherited environment before the utility is invoked. basically you're adding/overriding one lil variable before the command goes live.utilityโ The name of the utility to be invoked. If the utility operand names any of the special built-in utilities in Section 2.14, Special Built-In Utilities, the results are undefined. ๐จ undefined behavior alert, we don't do that.argumentโ A string to pass as an argument for the invoked utility.
STDIN ๐
Not used. she does not read from stdin, she's not interested.
INPUT FILES ๐
None.
ENVIRONMENT VARIABLES ๐
The following environment variables shall affect the execution of env:
LANGโ Provide a default value for the internationalization variables that are unset or null. (See the Base Definitions volume of POSIX.1โ2017, Section 8.2, Internationalization Variables for the precedence of internationalization variables used to determine the values of locale categories.)LC_ALLโ If set to a non-empty string value, override the values of all the other internationalization variables. she's the main character, she overrides everyone. ๐LC_CTYPEโ 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).LC_MESSAGESโ Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error.NLSPATHโ Determine the location of message catalogs for the processing ofLC_MESSAGES.PATHโ Determine the location of the utility, as described in the Base Definitions volume of POSIX.1โ2017, Chapter 8, Environment Variables. IfPATHis specified as aname=valueoperand toenv, the value given shall be used in the search for utility. lowkey important: if you pass a newPATHin, she uses THAT one to go find your command. ๐
ASYNCHRONOUS EVENTS โญ
Default.
STDOUT ๐ง
If no utility operand is specified, each name=value pair in the resulting environment shall be written in the form:
"%s=%s\n", <name>, <value>
If the utility operand is specified, the env utility shall not write to standard output. like, she's busy running your thing, she's not gonna yap to stdout too.
STDERR ๐
The standard error shall be used only for diagnostic messages.
OUTPUT FILES ๐
None.
EXTENDED DESCRIPTION ๐ธ
None.
EXIT STATUS ๐ฅ
If utility is invoked, the exit status of env shall be the exit status of utility; otherwise, the env utility shall exit with one of the following values:
0โ Theenvutility completed successfully. slay. โจ1-125โ An error occurred in theenvutility.126โ The utility specified by utility was found but could not be invoked.127โ The utility specified by utility could not be found.
CONSEQUENCES OF ERRORS ๐
Default.
The following sections are informative.
APPLICATION USAGE ๐ซถ
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 reason.
Historical implementations of the env utility use the execvp() or execlp() functions defined in the System Interfaces volume of POSIX.1โ2017 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. ๐ซ so like, if your command is a shell function or a shell-only built-in, env is not gonna find it. sorry bestie, that's just the lore.
EXAMPLES ๐
The following command:
env -i PATH=/mybin:"$PATH" $(getconf V7_ENV) mygrep xyz myfile
invokes the command mygrep with a new PATH value as the only entry in its environment other than any variables required by the implementation for conformance. In this case, PATH is used to locate mygrep, which is expected to reside in /mybin. look at her go. ๐
RATIONALE ๐ง
As with all other utilities that invoke other utilities, this volume of POSIX.1โ2017 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 removed - option in a manner compatible with the Utility Syntax Guidelines. It is possible to create a non-conforming environment using the -i 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 PATH for conforming utilities:
IFS='
'
# The preceding value should be <space><tab><newline>.
# Set IFS to its default value.
set -f
# disable pathname expansion
\unalias -a
# 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
# itself.
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 env is redundant since the same effect is achieved by:
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. so yeah, she's not redundant, she does MORE. she stays booked and busy. ๐
FUTURE DIRECTIONS ๐ฎ
None.
SEE ALSO ๐
Section 2.14, Special Built-In Utilities, Section 2.5, Parameters and Variables
The Base Definitions volume of POSIX.1โ2017, Chapter 8, Environment Variables, Section 12.2, Utility Syntax Guidelines
COPYRIGHT ๐
Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 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 .
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 https://www.kernel.org/doc/man-pages/reporting_bugs.html .
okay that's the whole thing bestie, every last crumb of it, no details left behind. ๐ซถโจ this lil masterpiece came from IEEE/The Open Group, 2017, and yes the page is literally called ENV(1P). go forth and env responsibly. ๐
๐
๐ฆ where this page comes from
- alpine 3.22: man-pages-posix 2017a-r0 ยท custom
- alpine 3.23: man-pages-posix 2017a-r0 ยท custom
- alpine 3.24: man-pages-posix 2017a-r0 ยท custom
- arch rolling: man-pages 6.19-1
- arch rolling: man-pages 6.20-1 ยท BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages-posix 2017a
- opensuse-leap 16.0: man-pages-posix 2017a-160000.4.1 ยท SUSE-IEEE
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms