{"id":5812,"date":"2022-12-20T18:57:36","date_gmt":"2022-12-20T21:57:36","guid":{"rendered":"http:\/\/lode.uno\/linux-man\/index.php\/2022\/12\/20\/env-man1p\/"},"modified":"2022-12-20T18:57:36","modified_gmt":"2022-12-20T21:57:36","slug":"env-man1p","status":"publish","type":"post","link":"https:\/\/lode.uno\/linux-man\/2022\/12\/20\/env-man1p\/","title":{"rendered":"ENV (man1p)"},"content":{"rendered":"<h1 align=\"center\">ENV<\/h1>\n<p> <a href=\"#PROLOG\">PROLOG<\/a><br \/> <a href=\"#NAME\">NAME<\/a><br \/> <a href=\"#SYNOPSIS\">SYNOPSIS<\/a><br \/> <a href=\"#DESCRIPTION\">DESCRIPTION<\/a><br \/> <a href=\"#OPTIONS\">OPTIONS<\/a><br \/> <a href=\"#OPERANDS\">OPERANDS<\/a><br \/> <a href=\"#STDIN\">STDIN<\/a><br \/> <a href=\"#INPUT FILES\">INPUT FILES<\/a><br \/> <a href=\"#ENVIRONMENT VARIABLES\">ENVIRONMENT VARIABLES<\/a><br \/> <a href=\"#ASYNCHRONOUS EVENTS\">ASYNCHRONOUS EVENTS<\/a><br \/> <a href=\"#STDOUT\">STDOUT<\/a><br \/> <a href=\"#STDERR\">STDERR<\/a><br \/> <a href=\"#OUTPUT FILES\">OUTPUT FILES<\/a><br \/> <a href=\"#EXTENDED DESCRIPTION\">EXTENDED DESCRIPTION<\/a><br \/> <a href=\"#EXIT STATUS\">EXIT STATUS<\/a><br \/> <a href=\"#CONSEQUENCES OF ERRORS\">CONSEQUENCES OF ERRORS<\/a><br \/> <a href=\"#APPLICATION USAGE\">APPLICATION USAGE<\/a><br \/> <a href=\"#EXAMPLES\">EXAMPLES<\/a><br \/> <a href=\"#RATIONALE\">RATIONALE<\/a><br \/> <a href=\"#FUTURE DIRECTIONS\">FUTURE DIRECTIONS<\/a><br \/> <a href=\"#SEE ALSO\">SEE ALSO<\/a><br \/> <a href=\"#COPYRIGHT\">COPYRIGHT<\/a> <\/p>\n<hr>\n<h2>PROLOG <a name=\"PROLOG\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">This manual page is part of the POSIX Programmer\u2019s 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.<\/p>\n<h2>NAME <a name=\"NAME\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">env \u2014 set the environment for command invocation<\/p>\n<h2>SYNOPSIS <a name=\"SYNOPSIS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">env <b>[<\/b>-i<b>] [<\/b><i>name<\/i>=<i>value<\/i><b>]<\/b>&#8230; <b>[<\/b><i>utility<\/i> <b>[<\/b><i>argument<\/i>&#8230;<b>]]<\/b><\/p>\n<h2>DESCRIPTION <a name=\"DESCRIPTION\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">The <i>env<\/i> utility shall obtain the current environment, modify it according to its arguments, then invoke the utility named by the <i>utility<\/i> operand with the modified environment.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Optional arguments shall be passed to <i>utility<\/i>.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">If no <i>utility<\/i> operand is specified, the resulting environment shall be written to the standard output, with one <i>name<\/i>=<i>value<\/i> pair per line.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">If the first argument is <b>\u2019\u2212\u2019<\/b>, the results are unspecified.<\/p>\n<h2>OPTIONS <a name=\"OPTIONS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">The <i>env<\/i> utility shall conform to the Base Definitions volume of POSIX.1-2017, <i>Section 12.2<\/i>, <i>Utility Syntax Guidelines<\/i>, except for the unspecified usage of <b>\u2019\u2212\u2019<\/b>.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The following options shall be supported:<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"3%\">\n<p><b>\u2212i<\/b><\/p>\n<\/td>\n<td width=\"12%\"><\/td>\n<td width=\"74%\">\n<p>Invoke <i>utility<\/i> with exactly the environment specified by the arguments; the inherited environment shall be ignored completely.<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<h2>OPERANDS <a name=\"OPERANDS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">The following operands shall be supported: <i><br \/> name<\/i>=<i>value<\/i><\/p>\n<p style=\"margin-left:26%;\">Arguments of the form <i>name<\/i>=<i>value<\/i> shall modify the execution environment, and shall be placed into the inherited environment before the <i>utility<\/i> is invoked.<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"12%\">\n<p><i>utility<\/i><\/p>\n<\/td>\n<td width=\"3%\"><\/td>\n<td width=\"74%\">\n<p>The name of the utility to be invoked. If the <i>utility<\/i> operand names any of the special built-in utilities in <i>Section 2.14<\/i>, <i>Special Built-In Utilities<\/i>, the results are undefined.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"12%\">\n<p><i>argument<\/i><\/p>\n<\/td>\n<td width=\"3%\"><\/td>\n<td width=\"74%\">\n<p>A string to pass as an argument for the invoked utility.<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<h2>STDIN <a name=\"STDIN\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Not used.<\/p>\n<h2>INPUT FILES <a name=\"INPUT FILES\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">None.<\/p>\n<h2>ENVIRONMENT VARIABLES <a name=\"ENVIRONMENT VARIABLES\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">The following environment variables shall affect the execution of <i>env<\/i>:<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"12%\">\n<p style=\"margin-top: 1em\"><i>LANG<\/i><\/p>\n<\/td>\n<td width=\"3%\"><\/td>\n<td width=\"74%\">\n<p style=\"margin-top: 1em\">Provide a default value for the internationalization variables that are unset or null. (See the Base Definitions volume of POSIX.1-2017, <i>Section 8.2<\/i>, <i>Internationalization Variables<\/i> for the precedence of internationalization variables used to determine the values of locale categories.)<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"12%\">\n<p><i>LC_ALL<\/i><\/p>\n<\/td>\n<td width=\"3%\"><\/td>\n<td width=\"74%\">\n<p>If set to a non-empty string value, override the values of all the other internationalization variables.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"12%\">\n<p><i>LC_CTYPE<\/i><\/p>\n<\/td>\n<td width=\"3%\"><\/td>\n<td width=\"74%\">\n<p>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).<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:11%;\"><i>LC_MESSAGES<\/i><\/p>\n<p style=\"margin-left:26%;\">Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error.<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"11%\">\n<p><i>NLSPATH<\/i><\/p>\n<\/td>\n<td width=\"4%\"><\/td>\n<td width=\"74%\">\n<p>Determine the location of message catalogs for the processing of <i>LC_MESSAGES<\/i>.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"11%\">\n<p><i>PATH<\/i><\/p>\n<\/td>\n<td width=\"4%\"><\/td>\n<td width=\"74%\">\n<p>Determine the location of the <i>utility<\/i>, as described in the Base Definitions volume of POSIX.1-2017, <i>Chapter 8<\/i>, <i>Environment Variables<\/i>. If <i>PATH<\/i> is specified as a <i>name<\/i>=<i>value<\/i> operand to <i>env<\/i>, the <i>value<\/i> given shall be used in the search for <i>utility<\/i>.<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<h2>ASYNCHRONOUS EVENTS <a name=\"ASYNCHRONOUS EVENTS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Default.<\/p>\n<h2>STDOUT <a name=\"STDOUT\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">If no <i>utility<\/i> operand is specified, each <i>name<\/i>=<i>value<\/i> pair in the resulting environment shall be written in the form:<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">&#8220;%s=%sn&#8221;, <<i>name<\/i>>, <<i>value<\/i>><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">If the <i>utility<\/i> operand is specified, the <i>env<\/i> utility shall not write to standard output.<\/p>\n<h2>STDERR <a name=\"STDERR\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">The standard error shall be used only for diagnostic messages.<\/p>\n<h2>OUTPUT FILES <a name=\"OUTPUT FILES\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">None.<\/p>\n<h2>EXTENDED DESCRIPTION <a name=\"EXTENDED DESCRIPTION\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">None.<\/p>\n<h2>EXIT STATUS <a name=\"EXIT STATUS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">If <i>utility<\/i> is invoked, the exit status of <i>env<\/i> shall be the exit status of <i>utility<\/i>; otherwise, the <i>env<\/i> utility shall exit with one of the following values:<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"7%\">\n<p style=\"margin-top: 1em\">0<\/p>\n<\/td>\n<td width=\"5%\"><\/td>\n<td width=\"77%\">\n<p style=\"margin-top: 1em\">The <i>env<\/i> utility completed successfully.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"7%\">\n<p>1\u2212125<\/p>\n<\/td>\n<td width=\"5%\"><\/td>\n<td width=\"77%\">\n<p>An error occurred in the <i>env<\/i> utility.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"7%\">\n<p>126<\/p>\n<\/td>\n<td width=\"5%\"><\/td>\n<td width=\"77%\">\n<p>The utility specified by <i>utility<\/i> was found but could not be invoked.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"7%\">\n<p>127<\/p>\n<\/td>\n<td width=\"5%\"><\/td>\n<td width=\"77%\">\n<p>The utility specified by <i>utility<\/i> could not be found.<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<h2>CONSEQUENCES OF ERRORS <a name=\"CONSEQUENCES OF ERRORS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Default.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><i>The following sections are informative.<\/i><\/p>\n<h2>APPLICATION USAGE <a name=\"APPLICATION USAGE\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">The <i>command<\/i>, <i>env<\/i>, <i>nice<\/i>, <i>nohup<\/i>, <i>time<\/i>, and <i>xargs<\/i> utilities have been specified to use exit code 127 if an error occurs so that applications can distinguish \u2018\u2018failure to find a utility\u2019\u2019 from \u2018\u2018invoked utility exited with an error indication\u2019\u2019. The value 127 was chosen because it is not commonly used for other meanings; most utilities use small values for \u2018\u2018normal error conditions\u2019\u2019 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 <i>exec<\/i> the utility fail with <b>[ENOENT]<\/b>, and uses 126 when any attempt to <i>exec<\/i> the utility fails for any other reason.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Historical implementations of the <i>env<\/i> utility use the <i>execvp<\/i>() or <i>execlp<\/i>() 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.<\/p>\n<h2>EXAMPLES <a name=\"EXAMPLES\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">The following command:<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">env -i PATH=\/mybin:&#8221;$PATH&#8221; $(getconf V7_ENV) mygrep xyz myfile<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">invokes the command <i>mygrep<\/i> with a new <i>PATH<\/i> value as the only entry in its environment other than any variables required by the implementation for conformance. In this case, <i>PATH<\/i> is used to locate <i>mygrep<\/i>, which is expected to reside in <b>\/mybin<\/b>.<\/p>\n<h2>RATIONALE <a name=\"RATIONALE\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">As with all other utilities that invoke other utilities, this volume of POSIX.1-2017 only specifies what <i>env<\/i> 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 <i>env<\/i>.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The <b>\u2212i<\/b> option was added to allow the functionality of the removed <b>\u2212<\/b> option in a manner compatible with the Utility Syntax Guidelines. It is possible to create a non-conforming environment using the <b>\u2212i<\/b> 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 <i>PATH<\/i> for conforming utilities:<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">IFS=&#8217; <br \/> &#8216; <br \/> # The preceding value should be <space><tab><newline>. <br \/> # Set IFS to its default value.<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">set -f <br \/> # disable pathname expansion<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">unalias -a <br \/> # Unset all possible aliases. <br \/> # Note that unalias is escaped to prevent an alias <br \/> # being used for unalias. <br \/> # This step is not strictly necessary, since aliases are not inherited, <br \/> # and the ENV environment variable is only used by interactive shells, <br \/> # the only way any aliases can exist in a script is if it defines them <br \/> # itself.<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">unset -f env getconf <br \/> # Ensure env and getconf are not user functions.<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">env -i $(getconf V7_ENV) PATH=&#8221;$(getconf PATH)&#8221; command<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Some have suggested that <i>env<\/i> is redundant since the same effect is achieved by:<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">name=value &#8230; utility <b>[<\/b> argument &#8230; <b>]<\/b><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The example is equivalent to <i>env<\/i> 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 <i>env<\/i> utility also writes out the current environment if invoked without arguments. There is sufficient functionality beyond what the example provides to justify inclusion of <i>env<\/i>.<\/p>\n<h2>FUTURE DIRECTIONS <a name=\"FUTURE DIRECTIONS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">None.<\/p>\n<h2>SEE ALSO <a name=\"SEE ALSO\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><i>Section 2.14<\/i>, <i>Special Built-In Utilities<\/i>, <i>Section 2.5<\/i>, <i>Parameters and Variables<\/i><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The Base Definitions volume of POSIX.1-2017, <i>Chapter 8<\/i>, <i>Environment Variables<\/i>, <i>Section 12.2<\/i>, <i>Utility Syntax Guidelines<\/i><\/p>\n<h2>COPYRIGHT <a name=\"COPYRIGHT\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology &#8212; 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 .<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">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 .<\/p>\n<hr>\n","protected":false},"excerpt":{"rendered":"<p>  env \u2014 set the environment for command invocation <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3782,1],"tags":[2572,2511],"class_list":["post-5812","post","type-post","status-publish","format-standard","hentry","category-1p-posix-comandos-generales","category-sin-categoria","tag-env","tag-man1p"],"gutentor_comment":0,"_links":{"self":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/5812","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/comments?post=5812"}],"version-history":[{"count":0,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/5812\/revisions"}],"wp:attachment":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/media?parent=5812"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/categories?post=5812"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/tags?post=5812"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}