isposix

Un outil pour savoir si une commande est posix - retour accueil

git clone git://bebou.netlib.re/isposix
Log | Files | Refs | README |

env.html (15489B)


      1 <!-- Copyright 2001-2024 IEEE and The Open Group, All Rights Reserved -->
      2 <!DOCTYPE HTML>
      3 <html lang="en">
      4 <head>
      5 <meta name="generator" content="HTML Tidy for HTML5 for Linux version 5.8.0">
      6 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
      7 <link type="text/css" rel="stylesheet" href="style.css"><!-- Generated by The Open Group rhtm tool v1.2.4 -->
      8 <!-- Copyright (c) 2001-2024 The Open Group, All Rights Reserved -->
      9 <title>env</title>
     10 </head>
     11 <body bgcolor="white">
     12 <div class="NAVHEADER">
     13 <table summary="Header navigation table" class="nav" width="100%" border="0" cellpadding="0" cellspacing="0">
     14 <tr class="nav">
     15 <td class="nav" width="15%" align="left" valign="bottom"><a href="../utilities/ed.html" accesskey="P">&lt;&lt;&lt;
     16 Previous</a></td>
     17 <td class="nav" width="70%" align="center" valign="bottom"><a href="contents.html">Home</a></td>
     18 <td class="nav" width="15%" align="right" valign="bottom"><a href="../utilities/ex.html" accesskey="N">Next &gt;&gt;&gt;</a></td>
     19 </tr>
     20 </table>
     21 <hr align="left" width="100%"></div>
     22 <script language="JavaScript" src="../jscript/codes.js"></script><basefont size="3">
     23 <center><font size="2">The Open Group Base Specifications Issue 8<br>
     24 IEEE Std 1003.1-2024<br>
     25 Copyright © 2001-2024 The IEEE and The Open Group</font></center>
     26 <hr size="2" noshade>
     27 <a name="top" id="top"></a> <a name="env" id="env"></a> <a name="tag_20_39" id="tag_20_39"></a><!-- env -->
     28 <h4 class="mansect"><a name="tag_20_39_01" id="tag_20_39_01"></a>NAME</h4>
     29 <blockquote>env — set the environment for command invocation</blockquote>
     30 <h4 class="mansect"><a name="tag_20_39_02" id="tag_20_39_02"></a>SYNOPSIS</h4>
     31 <blockquote class="synopsis">
     32 <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>
     33 <b>[</b><i>argument</i><tt>...</tt><b>]]</b></code></p>
     34 </blockquote>
     35 <h4 class="mansect"><a name="tag_20_39_03" id="tag_20_39_03"></a>DESCRIPTION</h4>
     36 <blockquote>
     37 <p>The <i>env</i> utility shall obtain the current environment, modify it according to its arguments, then invoke the utility named
     38 by the <i>utility</i> operand with the modified environment.</p>
     39 <p>Optional arguments shall be passed to <i>utility</i>.</p>
     40 <p>If no <i>utility</i> operand is specified, the resulting environment shall be written to the standard output, with one
     41 <i>name</i>=<i>value</i> pair per line.</p>
     42 <p>If the first argument is <tt>'-'</tt>, the results are unspecified.</p>
     43 </blockquote>
     44 <h4 class="mansect"><a name="tag_20_39_04" id="tag_20_39_04"></a>OPTIONS</h4>
     45 <blockquote>
     46 <p>The <i>env</i> utility shall conform to XBD <a href="../basedefs/V1_chap12.html#tag_12_02"><i>12.2 Utility Syntax
     47 Guidelines</i></a> , except for the unspecified usage of <tt>'-'</tt>.</p>
     48 <p>The following options shall be supported:</p>
     49 <dl compact>
     50 <dd></dd>
     51 <dt><b>-i</b></dt>
     52 <dd>Invoke <i>utility</i> with exactly the environment specified by the arguments; the inherited environment shall be ignored
     53 completely.</dd>
     54 </dl>
     55 </blockquote>
     56 <h4 class="mansect"><a name="tag_20_39_05" id="tag_20_39_05"></a>OPERANDS</h4>
     57 <blockquote>
     58 <p>The following operands shall be supported:</p>
     59 <dl compact>
     60 <dd></dd>
     61 <dt><i>name</i>=<i>value</i></dt>
     62 <dd>Arguments of the form <i>name</i>=<i>value</i> shall modify the execution environment, and shall be placed into the inherited
     63 environment before the <i>utility</i> is invoked.</dd>
     64 <dt><i>utility</i></dt>
     65 <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=
     66 "../utilities/V3_chap02.html#tag_19_15"><i>2.15 Special Built-In Utilities</i></a> , the results are undefined.</dd>
     67 <dt><i>argument</i></dt>
     68 <dd>A string to pass as an argument for the invoked utility.</dd>
     69 </dl>
     70 </blockquote>
     71 <h4 class="mansect"><a name="tag_20_39_06" id="tag_20_39_06"></a>STDIN</h4>
     72 <blockquote>
     73 <p>Not used.</p>
     74 </blockquote>
     75 <h4 class="mansect"><a name="tag_20_39_07" id="tag_20_39_07"></a>INPUT FILES</h4>
     76 <blockquote>
     77 <p>None.</p>
     78 </blockquote>
     79 <h4 class="mansect"><a name="tag_20_39_08" id="tag_20_39_08"></a>ENVIRONMENT VARIABLES</h4>
     80 <blockquote>
     81 <p>The following environment variables shall affect the execution of <i>env</i>:</p>
     82 <dl compact>
     83 <dd></dd>
     84 <dt><i>LANG</i></dt>
     85 <dd>Provide a default value for the internationalization variables that are unset or null. (See XBD <a href=
     86 "../basedefs/V1_chap08.html#tag_08_02"><i>8.2 Internationalization Variables</i></a> for the precedence of internationalization
     87 variables used to determine the values of locale categories.)</dd>
     88 <dt><i>LC_ALL</i></dt>
     89 <dd>If set to a non-empty string value, override the values of all the other internationalization variables.</dd>
     90 <dt><i>LC_CTYPE</i></dt>
     91 <dd>Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single-byte as
     92 opposed to multi-byte characters in arguments).</dd>
     93 <dt><i>LC_MESSAGES</i></dt>
     94 <dd><br>
     95 Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error.</dd>
     96 <dt><i>NLSPATH</i></dt>
     97 <dd><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">
     98 Determine the location of messages objects and message catalogs. <img src="../images/opt-end.gif" alt="[Option End]" border=
     99 "0"></dd>
    100 <dt><i>PATH</i></dt>
    101 <dd>Determine the location of the <i>utility</i>, as described in XBD <a href="../basedefs/V1_chap08.html#tag_08"><i>8. Environment
    102 Variables</i></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
    103 be used in the search for <i>utility</i>.</dd>
    104 </dl>
    105 </blockquote>
    106 <h4 class="mansect"><a name="tag_20_39_09" id="tag_20_39_09"></a>ASYNCHRONOUS EVENTS</h4>
    107 <blockquote>
    108 <p>Default.</p>
    109 </blockquote>
    110 <h4 class="mansect"><a name="tag_20_39_10" id="tag_20_39_10"></a>STDOUT</h4>
    111 <blockquote>
    112 <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
    113 the form:</p>
    114 <pre>
    115 <tt>"%s=%s\n", &lt;</tt><i>name</i><tt>&gt;, &lt;</tt><i>value</i><tt>&gt;
    116 </tt></pre>
    117 <p>If the <i>utility</i> operand is specified, the <i>env</i> utility shall not write to standard output.</p>
    118 </blockquote>
    119 <h4 class="mansect"><a name="tag_20_39_11" id="tag_20_39_11"></a>STDERR</h4>
    120 <blockquote>
    121 <p>The standard error shall be used only for diagnostic messages.</p>
    122 </blockquote>
    123 <h4 class="mansect"><a name="tag_20_39_12" id="tag_20_39_12"></a>OUTPUT FILES</h4>
    124 <blockquote>
    125 <p>None.</p>
    126 </blockquote>
    127 <h4 class="mansect"><a name="tag_20_39_13" id="tag_20_39_13"></a>EXTENDED DESCRIPTION</h4>
    128 <blockquote>
    129 <p>None.</p>
    130 </blockquote>
    131 <h4 class="mansect"><a name="tag_20_39_14" id="tag_20_39_14"></a>EXIT STATUS</h4>
    132 <blockquote>
    133 <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
    134 <i>env</i> utility shall exit with one of the following values:</p>
    135 <dl compact>
    136 <dd></dd>
    137 <dt>&nbsp;&nbsp;&nbsp;&nbsp;0</dt>
    138 <dd>The <i>env</i> utility completed successfully.</dd>
    139 <dt>1-125</dt>
    140 <dd>An error occurred in the <i>env</i> utility.</dd>
    141 <dt>&nbsp;&nbsp;126</dt>
    142 <dd>The utility specified by <i>utility</i> was found but could not be invoked.</dd>
    143 <dt>&nbsp;&nbsp;127</dt>
    144 <dd>The utility specified by <i>utility</i> could not be found.</dd>
    145 </dl>
    146 </blockquote>
    147 <h4 class="mansect"><a name="tag_20_39_15" id="tag_20_39_15"></a>CONSEQUENCES OF ERRORS</h4>
    148 <blockquote>
    149 <p>Default.</p>
    150 </blockquote>
    151 <hr>
    152 <div class="box"><em>The following sections are informative.</em></div>
    153 <h4 class="mansect"><a name="tag_20_39_16" id="tag_20_39_16"></a>APPLICATION USAGE</h4>
    154 <blockquote>
    155 <p>The <a href="../utilities/command.html"><i>command</i></a>, <i>env</i>, <a href="../utilities/nice.html"><i>nice</i></a>,
    156 <a href="../utilities/nohup.html"><i>nohup</i></a>, <a href="../utilities/time.html"><i>time</i></a>, <a href=
    157 "../utilities/timeout.html"><i>timeout</i></a>, and <a href="../utilities/xargs.html"><i>xargs</i></a> utilities have been
    158 specified to use exit code 127 if a utility to be invoked cannot be found, so that applications can distinguish &quot;failure to find a
    159 utility&quot; from &quot;invoked utility exited with an error indication&quot;. The value 127 was chosen because it is not commonly used for
    160 other meanings; most utilities use small values for &quot;normal error conditions&quot; and the values above 128 can be confused with
    161 termination due to receipt of a signal. The value 126 was chosen in a similar manner to indicate that the utility could be found,
    162 but not invoked. Some scripts produce meaningful error messages differentiating the 126 and 127 cases. The distinction between exit
    163 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
    164 uses 126 when any attempt to <i>exec</i> the utility fails for any other reason.</p>
    165 <p>Historical implementations of the <i>env</i> utility use the <a href="../functions/execvp.html"><i>execvp</i>()</a> or <a href=
    166 "../functions/execlp.html"><i>execlp</i>()</a> functions defined in the System Interfaces volume of POSIX.1-2024 to invoke the
    167 specified utility; this provides better performance and keeps users from having to escape characters with special meaning to the
    168 shell. Therefore, shell functions, special built-ins, and built-ins that are only provided by the shell are not found by this type
    169 of <i>env</i> implementation. However, <i>env</i> can be implemented as a shell built-in, in which case it may be able to execute
    170 shell functions and built-ins. An application wishing to ensure execution of a non-built-in utility can use <a href=
    171 "../utilities/exec.html"><i>exec</i></a> in a subshell for this purpose.</p>
    172 </blockquote>
    173 <h4 class="mansect"><a name="tag_20_39_17" id="tag_20_39_17"></a>EXAMPLES</h4>
    174 <blockquote>
    175 <p>The following command:</p>
    176 <pre>
    177 <tt>env -i PATH=/mybin:"$PATH" $(getconf V7_ENV) mygrep xyz myfile
    178 </tt></pre>
    179 <p>invokes the command <i>mygrep</i> with a new <i>PATH</i> value as the only entry in its environment other than any variables
    180 required by the implementation for conformance. In this case, <i>PATH</i> is used to locate <i>mygrep</i>, which is expected to
    181 reside in <b>/mybin</b>.</p>
    182 </blockquote>
    183 <h4 class="mansect"><a name="tag_20_39_18" id="tag_20_39_18"></a>RATIONALE</h4>
    184 <blockquote>
    185 <p>As with all other utilities that invoke other utilities, this volume of POSIX.1-2024 only specifies what <i>env</i> does with
    186 standard input, standard output, standard error, input files, and output files. If a utility is executed, it is not constrained by
    187 the specification of input and output by <i>env</i>.</p>
    188 <p>The <b>-i</b> option was added to allow the functionality of the removed <b>-</b> option in a manner compatible with the Utility
    189 Syntax Guidelines. It is possible to create a non-conforming environment using the <b>-i</b> option, as it may remove environment
    190 variables required by the implementation for conformance. The following will preserve these environment variables as well as
    191 preserve the <i>PATH</i> for conforming utilities:</p>
    192 <pre>
    193 <tt>IFS='
    194 '
    195 # The preceding value should be &lt;space&gt;&lt;tab&gt;&lt;newline&gt;.
    196 # Set IFS to its default value.
    197 <br>
    198 set -f
    199 # disable pathname expansion
    200 <br>
    201 \unalias -a
    202 # Unset all possible aliases.
    203 # Note that unalias is escaped to prevent an alias
    204 # being used for unalias.
    205 # This step is not strictly necessary, since aliases are not inherited,
    206 # and the ENV environment variable is only used by interactive shells,
    207 # the only way any aliases can exist in a script is if it defines them
    208 # itself.
    209 <br>
    210 unset -f env getconf
    211 # Ensure env and getconf are not user functions.
    212 <br>
    213 env -i $(getconf V7_ENV) PATH="$(getconf PATH)" command
    214 </tt></pre>
    215 <p>Some have suggested that <i>env</i> is redundant since the same effect is achieved by:</p>
    216 <pre>
    217 <tt>name=value ... utility </tt><b>[</b><tt> argument ... </tt><b>]</b><tt>
    218 </tt></pre>
    219 <p>The example is equivalent to <i>env</i> when an environment variable is being added to the environment of the command, but not
    220 when the environment is being set to the given value. The <i>env</i> utility also writes out the current environment if invoked
    221 without arguments. There is sufficient functionality beyond what the example provides to justify inclusion of <i>env</i>.</p>
    222 </blockquote>
    223 <h4 class="mansect"><a name="tag_20_39_19" id="tag_20_39_19"></a>FUTURE DIRECTIONS</h4>
    224 <blockquote>
    225 <p>None.</p>
    226 </blockquote>
    227 <h4 class="mansect"><a name="tag_20_39_20" id="tag_20_39_20"></a>SEE ALSO</h4>
    228 <blockquote>
    229 <p><a href="../utilities/V3_chap02.html#tag_19_15"><i>2.15 Special Built-In Utilities</i></a> , <a href=
    230 "../utilities/V3_chap02.html#tag_19_05"><i>2.5 Parameters and Variables</i></a></p>
    231 <p>XBD <a href="../basedefs/V1_chap08.html#tag_08"><i>8. Environment Variables</i></a> , <a href=
    232 "../basedefs/V1_chap12.html#tag_12_02"><i>12.2 Utility Syntax Guidelines</i></a></p>
    233 </blockquote>
    234 <h4 class="mansect"><a name="tag_20_39_21" id="tag_20_39_21"></a>CHANGE HISTORY</h4>
    235 <blockquote>
    236 <p>First released in Issue 2.</p>
    237 </blockquote>
    238 <h4 class="mansect"><a name="tag_20_39_22" id="tag_20_39_22"></a>Issue 7</h4>
    239 <blockquote>
    240 <p>Austin Group Interpretation 1003.1-2001 #027 is applied, clarifying the behavior if the first argument is <tt>'-'</tt>.</p>
    241 <p>Austin Group Interpretation 1003.1-2001 #047 is applied, providing RATIONALE on how to use the <i>env</i> utility to preserve a
    242 conforming environment.</p>
    243 <p>SD5-XCU-ERN-97 is applied, updating the SYNOPSIS.</p>
    244 <p>The EXAMPLES section is revised to change the use of <i>env</i> <b>-i</b>.</p>
    245 </blockquote>
    246 <h4 class="mansect"><a name="tag_20_39_23" id="tag_20_39_23"></a>Issue 8</h4>
    247 <blockquote>
    248 <p>Austin Group Defect 1122 is applied, changing the description of <i>NLSPATH .</i></p>
    249 <p>Austin Group Defect 1157 is applied, adding a note about shell built-in implementations of <i>env</i> to the APPLICATION USAGE
    250 section.</p>
    251 <p>Austin Group Defect 1586 is applied, adding the <a href="../utilities/timeout.html"><i>timeout</i></a> utility.</p>
    252 <p>Austin Group Defect 1594 is applied, changing the APPLICATION USAGE section.</p>
    253 </blockquote>
    254 <div class="box"><em>End of informative text.</em></div>
    255 <hr>
    256 <p>&nbsp;</p>
    257 <a href="#top"><span class="topOfPage">return to top of page</span></a><br>
    258 <hr size="2" noshade>
    259 <center><font size="2">UNIX® is a registered Trademark of The Open Group.<br>
    260 POSIX™ is a Trademark of The IEEE.<br>
    261 Copyright © 2001-2024 The IEEE and The Open Group, All Rights Reserved<br>
    262 [ <a href="../mindex.html">Main Index</a> | <a href="../basedefs/contents.html">XBD</a> | <a href=
    263 "../functions/contents.html">XSH</a> | <a href="../utilities/contents.html">XCU</a> | <a href="../xrat/contents.html">XRAT</a>
    264 ]</font></center>
    265 <hr size="2" noshade>
    266 <div class="NAVHEADER">
    267 <table summary="Header navigation table" class="nav" width="100%" border="0" cellpadding="0" cellspacing="0">
    268 <tr class="nav">
    269 <td class="nav" width="15%" align="left" valign="bottom"><a href="../utilities/ed.html" accesskey="P">&lt;&lt;&lt;
    270 Previous</a></td>
    271 <td class="nav" width="70%" align="center" valign="bottom"><a href="contents.html">Home</a></td>
    272 <td class="nav" width="15%" align="right" valign="bottom"><a href="../utilities/ex.html" accesskey="N">Next &gt;&gt;&gt;</a></td>
    273 </tr>
    274 </table>
    275 <hr align="left" width="100%"></div>
    276 </body>
    277 </html>