Files
oldlinux-files/Ref-docs/POSIX/susv3/utilities/env.html
2024-02-19 00:21:47 -05:00

298 lines
11 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta name="generator" content="HTML Tidy, see www.w3.org">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link type="text/css" rel="stylesheet" href="style.css"><!-- Generated by The Open Group's rhtm tool v1.2.1 -->
<!-- Copyright (c) 2001 The Open Group, All Rights Reserved -->
<title>env</title>
</head>
<body bgcolor="white">
<script type="text/javascript" language="JavaScript" src="../jscript/codes.js">
</script>
<basefont size="3"> <a name="env"></a> <a name="tag_04_43"></a><!-- env -->
<!--header start-->
<center><font size="2">The Open Group Base Specifications Issue 6<br>
IEEE Std 1003.1-2001<br>
Copyright &copy; 2001 The IEEE and The Open Group, All Rights reserved.</font></center>
<!--header end-->
<hr size="2" noshade>
<h4><a name="tag_04_43_01"></a>NAME</h4>
<blockquote>env - set the environment for command invocation</blockquote>
<h4><a name="tag_04_43_02"></a>SYNOPSIS</h4>
<blockquote class="synopsis">
<p><code><tt>env</tt> <b>[</b><tt>-i</tt><b>][</b><i>name</i><tt>=</tt><i>value</i><b>]</b><tt>...</tt> <b>[</b><i>utility</i>
<b>[</b><i>argument</i><tt>...</tt><b>]]</b></code></p>
</blockquote>
<h4><a name="tag_04_43_03"></a>DESCRIPTION</h4>
<blockquote>
<p>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>
<p>Optional arguments shall be passed to <i>utility</i>.</p>
<p>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>
</blockquote>
<h4><a name="tag_04_43_04"></a>OPTIONS</h4>
<blockquote>
<p>The <i>env</i> utility shall conform to the Base Definitions volume of IEEE&nbsp;Std&nbsp;1003.1-2001, <a href=
"../basedefs/xbd_chap12.html#tag_12_02">Section 12.2, Utility Syntax Guidelines</a>.</p>
<p>The following options shall be supported:</p>
<dl compact>
<dt><b>-i</b></dt>
<dd>Invoke <i>utility</i> with exactly the environment specified by the arguments; the inherited environment shall be ignored
completely.</dd>
</dl>
</blockquote>
<h4><a name="tag_04_43_05"></a>OPERANDS</h4>
<blockquote>
<p>The following operands shall be supported:</p>
<dl compact>
<dt><i>name</i>=<i>value</i></dt>
<dd>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.</dd>
<dt><i>utility</i></dt>
<dd>The name of the utility to be invoked. If the <i>utility</i> operand names any of the special built-in utilities in <a href=
"xcu_chap02.html#tag_02_14"><i>Special Built-In Utilities</i></a> , the results are undefined.</dd>
<dt><i>argument</i></dt>
<dd>A string to pass as an argument for the invoked utility.</dd>
</dl>
</blockquote>
<h4><a name="tag_04_43_06"></a>STDIN</h4>
<blockquote>
<p>Not used.</p>
</blockquote>
<h4><a name="tag_04_43_07"></a>INPUT FILES</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_04_43_08"></a>ENVIRONMENT VARIABLES</h4>
<blockquote>
<p>The following environment variables shall affect the execution of <i>env</i>:</p>
<dl compact>
<dt><i>LANG</i></dt>
<dd>Provide a default value for the internationalization variables that are unset or null. (See the Base Definitions volume of
IEEE&nbsp;Std&nbsp;1003.1-2001, <a href="../basedefs/xbd_chap08.html#tag_08_02">Section 8.2, Internationalization Variables</a> for
the precedence of internationalization variables used to determine the values of locale categories.)</dd>
<dt><i>LC_ALL</i></dt>
<dd>If set to a non-empty string value, override the values of all the other internationalization variables.</dd>
<dt><i>LC_CTYPE</i></dt>
<dd>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).</dd>
<dt><i>LC_MESSAGES</i></dt>
<dd>Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard
error.</dd>
<dt><i>NLSPATH</i></dt>
<dd><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">
Determine the location of message catalogs for the processing of <i>LC_MESSAGES .</i> <img src="../images/opt-end.gif" alt=
"[Option End]" border="0"></dd>
<dt><i>PATH</i></dt>
<dd>Determine the location of the <i>utility</i>, as described in the Base Definitions volume of IEEE&nbsp;Std&nbsp;1003.1-2001, <a
href="../basedefs/xbd_chap08.html">Chapter 8, Environment Variables</a>. 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>.</dd>
</dl>
</blockquote>
<h4><a name="tag_04_43_09"></a>ASYNCHRONOUS EVENTS</h4>
<blockquote>
<p>Default.</p>
</blockquote>
<h4><a name="tag_04_43_10"></a>STDOUT</h4>
<blockquote>
<p>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>
<pre>
<tt>"%s=%s\n", &lt;</tt><i>name</i><tt>&gt;, &lt;</tt><i>value</i><tt>&gt;
</tt>
</pre>
<p>If the <i>utility</i> operand is specified, the <i>env</i> utility shall not write to standard output.</p>
</blockquote>
<h4><a name="tag_04_43_11"></a>STDERR</h4>
<blockquote>
<p>The standard error shall be used only for diagnostic messages.</p>
</blockquote>
<h4><a name="tag_04_43_12"></a>OUTPUT FILES</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_04_43_13"></a>EXTENDED DESCRIPTION</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_04_43_14"></a>EXIT STATUS</h4>
<blockquote>
<p>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>
<dl compact>
<dt>&nbsp;&nbsp;&nbsp;&nbsp;0</dt>
<dd>The <i>env</i> utility completed successfully.</dd>
<dt>1-125</dt>
<dd>An error occurred in the <i>env</i> utility.</dd>
<dt>&nbsp;&nbsp;126</dt>
<dd>The utility specified by <i>utility</i> was found but could not be invoked.</dd>
<dt>&nbsp;&nbsp;127</dt>
<dd>The utility specified by <i>utility</i> could not be found.</dd>
</dl>
</blockquote>
<h4><a name="tag_04_43_15"></a>CONSEQUENCES OF ERRORS</h4>
<blockquote>
<p>Default.</p>
</blockquote>
<hr>
<div class="box"><em>The following sections are informative.</em></div>
<h4><a name="tag_04_43_16"></a>APPLICATION USAGE</h4>
<blockquote>
<p>The <a href="../utilities/command.html"><i>command</i></a>, <i>env</i>, <a href="../utilities/nice.html"><i>nice</i></a>, <a
href="../utilities/nohup.html"><i>nohup</i></a>, <a href="../utilities/time.html"><i>time</i></a>, and <a href=
"../utilities/xargs.html"><i>xargs</i></a> utilities have been specified to use exit code 127 if an error occurs so that
applications can distinguish &quot;failure to find a utility&quot; from &quot;invoked utility exited with an error indication&quot;. The value 127
was chosen because it is not commonly used for other meanings; most utilities use small values for &quot;normal error conditions&quot; 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 [ENOENT], and uses 126 when any attempt to <i>exec</i> the utility fails for any other
reason.</p>
<p>Historical implementations of the <i>env</i> utility use the <a href="../functions/execvp.html"><i>execvp</i>()</a> or <a href=
"../functions/execlp.html"><i>execlp</i>()</a> functions defined in the System Interfaces volume of IEEE&nbsp;Std&nbsp;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.</p>
</blockquote>
<h4><a name="tag_04_43_17"></a>EXAMPLES</h4>
<blockquote>
<p>The following command:</p>
<pre>
<tt>env -i PATH=/mybin mygrep xyz myfile
</tt>
</pre>
<p>invokes the command <i>mygrep</i> with a new <i>PATH</i> value as the only entry in its environment. In this case, <i>PATH</i>
is used to locate <i>mygrep</i>, which then must reside in <b>/mybin</b>.</p>
</blockquote>
<h4><a name="tag_04_43_18"></a>RATIONALE</h4>
<blockquote>
<p>As with all other utilities that invoke other utilities, this volume of IEEE&nbsp;Std&nbsp;1003.1-2001 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>
<p>The <b>-i</b> option was added to allow the functionality of the withdrawn <b>-</b> option in a manner compatible with the
Utility Syntax Guidelines.</p>
<p>Some have suggested that <i>env</i> is redundant since the same effect is achieved by:</p>
<pre>
<tt>name=value ... utility</tt> <b>[</b> <tt>argument ...</tt> <b>]</b>
</pre>
<p>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>
</blockquote>
<h4><a name="tag_04_43_19"></a>FUTURE DIRECTIONS</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_04_43_20"></a>SEE ALSO</h4>
<blockquote>
<p><a href="xcu_chap02.html#tag_02_05"><i>Parameters and Variables</i></a> , <a href="xcu_chap02.html#tag_02_14"><i>Special
Built-In Utilities</i></a></p>
</blockquote>
<h4><a name="tag_04_43_21"></a>CHANGE HISTORY</h4>
<blockquote>
<p>First released in Issue 2.</p>
</blockquote>
<div class="box"><em>End of informative text.</em></div>
<hr>
<hr size="2" noshade>
<center><font size="2"><!--footer start-->
UNIX &reg; is a registered Trademark of The Open Group.<br>
POSIX &reg; is a registered Trademark of The IEEE.<br>
[ <a href="../mindex.html">Main Index</a> | <a href="../basedefs/contents.html">XBD</a> | <a href=
"../utilities/contents.html">XCU</a> | <a href="../functions/contents.html">XSH</a> | <a href="../xrat/contents.html">XRAT</a>
]</font></center>
<!--footer end-->
<hr size="2" noshade>
</body>
</html>