Un outil pour savoir si une commande est posix - retour accueil
git clone git://bebou.netlib.re/isposix
Log | Files | Refs | README |
xargs.html (32021B)
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>xargs</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/write.html" accesskey="P"><<< 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/xgettext.html" accesskey="N">Next 19 >>></a></td> 20 </tr> 21 </table> 22 <hr align="left" width="100%"></div> 23 <script language="JavaScript" src="../jscript/codes.js"></script><basefont size="3"> 24 <center><font size="2">The Open Group Base Specifications Issue 8<br> 25 IEEE Std 1003.1-2024<br> 26 Copyright © 2001-2024 The IEEE and The Open Group</font></center> 27 <hr size="2" noshade> 28 <a name="top" id="top"></a> <a name="xargs" id="xargs"></a> <a name="tag_20_152" id="tag_20_152"></a><!-- xargs --> 29 <h4 class="mansect"><a name="tag_20_152_01" id="tag_20_152_01"></a>NAME</h4> 30 <blockquote>xargs — construct argument lists and invoke utility</blockquote> 31 <h4 class="mansect"><a name="tag_20_152_02" id="tag_20_152_02"></a>SYNOPSIS</h4> 32 <blockquote class="synopsis"> 33 <p><code><tt><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> xargs</tt> <b>[</b><tt>-prtx</tt><b>] [</b><tt>-E</tt> 34 <i>eofstr</i><tt>|-0</tt><b>] [<img src="../images/opt-start.gif" border="0"></b><tt>-I</tt> <i>replstr</i><tt>|-L</tt> 35 <i>number</i><tt><img src="../images/opt-end.gif" border="0">|-n</tt> <i>number</i><b>]</b> <tt><br> 36 </tt> <b>[</b><tt>-s</tt> <i>size</i><b>] [</b><i>utility</i> 37 <b>[</b><i>argument</i><tt>...</tt><b>]]</b></code></p> 38 </blockquote> 39 <h4 class="mansect"><a name="tag_20_152_03" id="tag_20_152_03"></a>DESCRIPTION</h4> 40 <blockquote> 41 <p>The <i>xargs</i> utility shall construct a command line consisting of the <i>utility</i> and <i>argument</i> operands specified 42 followed by as many arguments read in sequence from standard input as fit in length and number constraints specified by the 43 options. The <i>xargs</i> utility shall then invoke the constructed command line and wait for its completion. This sequence shall 44 be repeated until one of the following occurs:</p> 45 <ul> 46 <li> 47 <p>An end-of-file condition is detected on standard input.</p> 48 </li> 49 <li> 50 <p>An argument consisting of just the logical end-of-file string (see the <b>-E</b> <i>eofstr</i> option) is found on standard 51 input after double-quote processing, <apostrophe> processing, and <backslash>-escape processing (see next paragraph). 52 All arguments up to but not including the argument consisting of just the logical end-of-file string shall be used as arguments in 53 constructed command lines.</p> 54 </li> 55 <li> 56 <p>An invocation of a constructed command line returns an exit status of 255.</p> 57 </li> 58 </ul> 59 <p>If the <b>-0</b> option is not specified, the application shall ensure that arguments in the standard input are delimited by 60 unquoted <blank> characters, unescaped <blank> characters, or <newline> characters, and quoting characters shall 61 be interpreted as follows:</p> 62 <ul> 63 <li> 64 <p>A string of zero or more non-double-quote (<tt>'"'</tt> ) non-<newline> characters can be quoted by enclosing them in 65 double-quotes.</p> 66 </li> 67 <li> 68 <p>A string of zero or more non-<apostrophe> (<tt>'\''</tt>) non-<newline> characters can be quoted by enclosing them 69 in <apostrophe> characters.</p> 70 </li> 71 <li> 72 <p>Any unquoted character can be escaped by preceding it with a <backslash>.</p> 73 </li> 74 </ul> 75 <p>Multiple adjacent delimiter characters shall be treated as a single delimiter. If the standard input is not empty and does not 76 end with a <newline>, the behavior is undefined (because the requirement in STDIN that the input is a text file is not met in 77 that case).</p> 78 <p>If the <b>-0</b> option is specified, the application shall ensure that arguments in the standard input are delimited by null 79 bytes. If multiple adjacent null bytes occur in the input, each null byte shall be treated as a delimiter. If the standard input is 80 not empty and does not end with a null byte, <i>xargs</i> should ignore the trailing non-null bytes (as this can signal incomplete 81 data) but may use them as the last argument passed to utility.</p> 82 <p>The utility named by <i>utility</i> shall be executed zero or more times until the end-of-file is reached or the logical end-of 83 file string is found. If no arguments are supplied on standard input, the utility named by <i>utility</i> shall be executed zero 84 times if the <b>-r</b> option is specified and shall be executed exactly once if the <b>-r</b> option is not specified. The results 85 are unspecified if the utility named by <i>utility</i> attempts to read from its standard input.</p> 86 <p>The generated command line length shall be the sum of the size in bytes of the utility name and each argument treated as 87 strings, including a null byte terminator for each of these strings. The <i>xargs</i> utility shall limit the command line length 88 such that when the command line is invoked, the combined argument and environment lists (see the <i>exec</i> family of functions in 89 the System Interfaces volume of POSIX.1-2024) shall not exceed {ARG_MAX}-2048 bytes. Within this constraint, if neither the 90 <b>-n</b> nor the <b>-s</b> option is specified, the default command line length shall be at least {LINE_MAX}.</p> 91 </blockquote> 92 <h4 class="mansect"><a name="tag_20_152_04" id="tag_20_152_04"></a>OPTIONS</h4> 93 <blockquote> 94 <p>The <i>xargs</i> utility shall conform to XBD <a href="../basedefs/V1_chap12.html#tag_12_02"><i>12.2 Utility Syntax 95 Guidelines</i></a> .</p> 96 <p>The following options shall be supported:</p> 97 <dl compact> 98 <dd></dd> 99 <dt><b>-E </b><i>eofstr</i></dt> 100 <dd>Use <i>eofstr</i> as the logical end-of-file string. If neither <b>-E</b> nor <b>-0</b> is specified, it is unspecified whether 101 the logical end-of-file string is the <underscore> character (<tt>'_'</tt>) or the end-of-file string capability is disabled. 102 When <i>eofstr</i> is the null string, the logical end-of-file string capability shall be disabled and <underscore> 103 characters shall be taken literally.</dd> 104 <dt><b>-I </b><i>replstr</i></dt> 105 <dd><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0"> 106 Insert mode: invoke <i>utility</i> for each argument from standard input. If <b>-0</b> is not specified, arguments in the standard 107 input shall be delimited only by unescaped <newline> characters, not by <blank> characters, and any unquoted unescaped 108 <blank> characters at the beginning of each line shall be ignored. The resulting argument shall be inserted in 109 <i>arguments</i> in place of each occurrence of <i>replstr</i>. At least five arguments in <i>arguments</i> can each contain one or 110 more instances of <i>replstr</i>. Each of these constructed arguments cannot grow larger than an implementation-defined limit 111 greater than or equal to 255 bytes. Option <b>-x</b> shall be forced on. <img src="../images/opt-end.gif" alt="[Option End]" 112 border="0"></dd> 113 <dt><b>-L </b><i>number</i></dt> 114 <dd><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0"> 115 Invoke <i>utility</i> for each set of <i>number</i> arguments from standard input. The last invocation of <i>utility</i> shall be 116 with fewer arguments if fewer than <i>number</i> remain. If the <b>-0</b> option is not specified, each line in the standard input 117 shall be treated as containing one argument except that empty lines shall be ignored and a line ending with a trailing unescaped 118 <blank> shall signal continuation to the next non-empty line, inclusive; such continuation shall result in removal of all 119 trailing unescaped <blank> characters and all <newline> characters that immediately follow them from the argument. 120 <img src="../images/opt-end.gif" alt="[Option End]" border="0"></dd> 121 <dt><b>-n </b><i>number</i></dt> 122 <dd>Invoke <i>utility</i> using as many standard input arguments as possible, up to <i>number</i> (a positive decimal integer) 123 arguments maximum. Fewer arguments shall be used if: 124 <ul> 125 <li> 126 <p>The command line length accumulated exceeds the size specified by the <b>-s</b> option (or {LINE_MAX} if there is no <b>-s</b> 127 option).</p> 128 </li> 129 <li> 130 <p>The last iteration has fewer than <i>number</i>, but not zero, operands remaining.</p> 131 </li> 132 </ul> 133 </dd> 134 <dt><b>-p</b></dt> 135 <dd>Prompt mode: the user is asked whether to execute <i>utility</i> at each invocation. Trace mode (<b>-t</b>) is turned on to 136 write the command instance to be executed, followed by a prompt to standard error. An affirmative response read from 137 <b>/dev/tty</b> shall execute the command; otherwise, that particular invocation of <i>utility</i> shall be skipped.</dd> 138 <dt><b>-r</b></dt> 139 <dd>Do not execute the utility named by <i>utility</i> if no arguments are supplied on standard input.</dd> 140 <dt><b>-s </b><i>size</i></dt> 141 <dd>Invoke <i>utility</i> using as many standard input arguments as possible yielding a command line length less than <i>size</i> 142 (a positive decimal integer) bytes. Fewer arguments shall be used if: 143 <ul> 144 <li> 145 <p>The total number of arguments exceeds that specified by the <b>-n</b> option.</p> 146 </li> 147 <li> 148 <p><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0"> 149 The total number of arguments exceeds that specified by the <b>-L</b> option. <img src="../images/opt-end.gif" alt="[Option End]" 150 border="0"></p> 151 </li> 152 <li> 153 <p>End-of-file is encountered on standard input before <i>size</i> bytes are accumulated.</p> 154 </li> 155 </ul> 156 <p>Values of <i>size</i> up to at least {LINE_MAX} bytes shall be supported, provided that the constraints specified in the 157 DESCRIPTION are met. It shall not be considered an error if a value larger than that supported by the implementation or exceeding 158 the constraints specified in the DESCRIPTION is given; <i>xargs</i> shall use the largest value it supports within the 159 constraints.</p> 160 </dd> 161 <dt><b>-t</b></dt> 162 <dd>Enable trace mode. Each generated command line shall be written to standard error just prior to invocation.</dd> 163 <dt><b>-x</b></dt> 164 <dd>Terminate if a constructed command line will not fit in the implied or specified size (see the <b>-s</b> option above).</dd> 165 <dt><b>-0</b></dt> 166 <dd>Use a null byte as the input argument delimiter and do not treat any other input bytes as special.</dd> 167 </dl> 168 <p>If the mutually exclusive <b>-0</b> and <b>-E</b> <i>eofstr</i> options are both specified, the behavior is unspecified, except 169 that if <i>eofstr</i> is the null string the behavior shall be the same as if <b>-0</b> was specified without <b>-E</b> 170 <i>eofstr</i>.</p> 171 </blockquote> 172 <h4 class="mansect"><a name="tag_20_152_05" id="tag_20_152_05"></a>OPERANDS</h4> 173 <blockquote> 174 <p>The following operands shall be supported:</p> 175 <dl compact> 176 <dd></dd> 177 <dt><i>utility</i></dt> 178 <dd>The name of the utility to be invoked, found by search path using the <i>PATH</i> environment variable, described in XBD 179 <a href="../basedefs/V1_chap08.html#tag_08"><i>8. Environment Variables</i></a> . If <i>utility</i> is omitted, the default shall 180 be the <a href="../utilities/echo.html"><i>echo</i></a> utility. If the <i>utility</i> operand names any of the special built-in 181 utilities in <a href="../utilities/V3_chap02.html#tag_19_15"><i>2.15 Special Built-In Utilities</i></a> , the results are 182 undefined.</dd> 183 <dt><i>argument</i></dt> 184 <dd>An initial option or operand for the invocation of <i>utility</i>.</dd> 185 </dl> 186 </blockquote> 187 <h4 class="mansect"><a name="tag_20_152_06" id="tag_20_152_06"></a>STDIN</h4> 188 <blockquote> 189 <p>If the <b>-0</b> option is not specified, the standard input shall be a text file and the results are unspecified if an 190 end-of-file condition is detected immediately following an escaped <newline>.</p> 191 <p>If the <b>-0</b> option is specified, the standard input need not be a text file, and <i>xargs</i> shall process the input as 192 bytes, not characters.</p> 193 </blockquote> 194 <h4 class="mansect"><a name="tag_20_152_07" id="tag_20_152_07"></a>INPUT FILES</h4> 195 <blockquote> 196 <p>The file <b>/dev/tty</b> shall be used to read responses required by the <b>-p</b> option.</p> 197 </blockquote> 198 <h4 class="mansect"><a name="tag_20_152_08" id="tag_20_152_08"></a>ENVIRONMENT VARIABLES</h4> 199 <blockquote> 200 <p>The following environment variables shall affect the execution of <i>xargs</i>:</p> 201 <dl compact> 202 <dd></dd> 203 <dt><i>LANG</i></dt> 204 <dd>Provide a default value for the internationalization variables that are unset or null. (See XBD <a href= 205 "../basedefs/V1_chap08.html#tag_08_02"><i>8.2 Internationalization Variables</i></a> for the precedence of internationalization 206 variables used to determine the values of locale categories.)</dd> 207 <dt><i>LC_ALL</i></dt> 208 <dd>If set to a non-empty string value, override the values of all the other internationalization variables.</dd> 209 <dt><i>LC_COLLATE</i></dt> 210 <dd><br> 211 Determine the locale for the behavior of ranges, equivalence classes, and multi-character collating elements used in the extended 212 regular expression defined for the <b>yesexpr</b> locale keyword in the <i>LC_MESSAGES</i> category.</dd> 213 <dt><i>LC_CTYPE</i></dt> 214 <dd>Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single-byte as 215 opposed to multi-byte characters in arguments and input files) and the behavior of character classes used in the extended regular 216 expression defined for the <b>yesexpr</b> locale keyword in the <i>LC_MESSAGES</i> category.</dd> 217 <dt><i>LC_MESSAGES</i></dt> 218 <dd><br> 219 Determine the locale used to process affirmative responses, and the locale used to affect the format and contents of diagnostic 220 messages and prompts written to standard error.</dd> 221 <dt><i>NLSPATH</i></dt> 222 <dd><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0"> 223 Determine the location of messages objects and message catalogs. <img src="../images/opt-end.gif" alt="[Option End]" border= 224 "0"></dd> 225 <dt><i>PATH</i></dt> 226 <dd>Determine the location of <i>utility</i>, as described in XBD <a href="../basedefs/V1_chap08.html#tag_08"><i>8. Environment 227 Variables</i></a> .</dd> 228 </dl> 229 </blockquote> 230 <h4 class="mansect"><a name="tag_20_152_09" id="tag_20_152_09"></a>ASYNCHRONOUS EVENTS</h4> 231 <blockquote> 232 <p>Default.</p> 233 </blockquote> 234 <h4 class="mansect"><a name="tag_20_152_10" id="tag_20_152_10"></a>STDOUT</h4> 235 <blockquote> 236 <p>Not used.</p> 237 </blockquote> 238 <h4 class="mansect"><a name="tag_20_152_11" id="tag_20_152_11"></a>STDERR</h4> 239 <blockquote> 240 <p>The standard error shall be used for diagnostic messages and the <b>-t</b> and <b>-p</b> options. If the <b>-t</b> option is 241 specified, the <i>utility</i> and its constructed argument list shall be written to standard error, as it will be invoked, prior to 242 invocation. If <b>-p</b> is specified, a prompt of the following format shall be written (in the POSIX locale):</p> 243 <pre> 244 <tt>"?..." 245 </tt></pre> 246 <p>at the end of the line of the output from <b>-t</b>.</p> 247 </blockquote> 248 <h4 class="mansect"><a name="tag_20_152_12" id="tag_20_152_12"></a>OUTPUT FILES</h4> 249 <blockquote> 250 <p>None.</p> 251 </blockquote> 252 <h4 class="mansect"><a name="tag_20_152_13" id="tag_20_152_13"></a>EXTENDED DESCRIPTION</h4> 253 <blockquote> 254 <p>None.</p> 255 </blockquote> 256 <h4 class="mansect"><a name="tag_20_152_14" id="tag_20_152_14"></a>EXIT STATUS</h4> 257 <blockquote> 258 <p>The following exit values shall be returned:</p> 259 <dl compact> 260 <dd></dd> 261 <dt> 0</dt> 262 <dd>Successful completion.</dd> 263 <dt>1-125</dt> 264 <dd>A command line meeting the specified requirements could not be assembled, one or more of the invocations of <i>utility</i> 265 returned a non-zero exit status, or some other error occurred.</dd> 266 <dt> 126</dt> 267 <dd>The utility specified by <i>utility</i> was found but could not be invoked.</dd> 268 <dt> 127</dt> 269 <dd>The utility specified by <i>utility</i> could not be found.</dd> 270 </dl> 271 </blockquote> 272 <h4 class="mansect"><a name="tag_20_152_15" id="tag_20_152_15"></a>CONSEQUENCES OF ERRORS</h4> 273 <blockquote> 274 <p>If a command line meeting the specified requirements cannot be assembled, the utility cannot be invoked, an invocation of the 275 utility is terminated by a signal, or an invocation of the utility exits with exit status 255, the <i>xargs</i> utility shall write 276 a diagnostic message and exit without processing any remaining input.</p> 277 </blockquote> 278 <hr> 279 <div class="box"><em>The following sections are informative.</em></div> 280 <h4 class="mansect"><a name="tag_20_152_16" id="tag_20_152_16"></a>APPLICATION USAGE</h4> 281 <blockquote> 282 <p>The 255 exit status allows a utility being used by <i>xargs</i> to tell <i>xargs</i> to terminate if it knows no further 283 invocations using the current data stream will succeed. Thus, <i>utility</i> should explicitly <a href= 284 "../utilities/V3_chap02.html#exit"><i>exit</i></a> with an appropriate value to avoid accidentally returning with 255.</p> 285 <p>Note that since input is parsed as lines (if <b>-0</b> is not specified), with <blank> characters separating arguments and 286 <backslash>, <apostrophe>, and double-quote characters used for quoting, if <i>xargs</i> is used to bundle the output 287 of commands like <a href="../utilities/find.html"><i>find</i></a> <i>dir</i> <b>-print</b> or <a href= 288 "../utilities/ls.html"><i>ls</i></a> into commands to be executed, unexpected results are likely if any filenames contain 289 <blank>, <newline>, or quoting characters. This can be solved by using the <b>-print0</b> primary of <a href= 290 "../utilities/find.html"><i>find</i></a> together with the <i>xargs</i> <b>-0</b> option, or by using <a href= 291 "../utilities/find.html"><i>find</i></a> to call a script that converts each file found into a quoted string that is then piped to 292 <i>xargs</i>, but in most cases it is preferable just to have <a href="../utilities/find.html"><i>find</i></a> do the argument 293 aggregation itself by using <b>-exec</b> with a <tt>'+'</tt> terminator instead of <tt>';'</tt>. Note that the quoting rules used 294 by <i>xargs</i> are not the same as in the shell. They were not made consistent here because existing applications depend on the 295 current rules. An easy (but inefficient) method that can be used to transform input consisting of one argument per line into a 296 quoted form that <i>xargs</i> interprets correctly is to precede each non-<newline> character with a <backslash>. More 297 efficient alternatives are shown in Example 2 and Example 5 below.</p> 298 <p>On implementations with a large value for {ARG_MAX}, <i>xargs</i> may produce command lines longer than {LINE_MAX}. For 299 invocation of utilities, this is not a problem. If <i>xargs</i> is being used to create a text file, users should explicitly set 300 the maximum command line length with the <b>-s</b> option.</p> 301 <p>The <a href="../utilities/command.html"><i>command</i></a>, <a href="../utilities/env.html"><i>env</i></a>, <a href= 302 "../utilities/nice.html"><i>nice</i></a>, <a href="../utilities/nohup.html"><i>nohup</i></a>, <a href= 303 "../utilities/time.html"><i>time</i></a>, <a href="../utilities/timeout.html"><i>timeout</i></a>, and <i>xargs</i> utilities have 304 been specified to use exit code 127 if a utility to be invoked cannot be found, so that applications can distinguish "failure to 305 find a utility" from "invoked utility exited with an error indication". The value 127 was chosen because it is not commonly used 306 for other meanings; most utilities use small values for "normal error conditions" and the values above 128 can be confused with 307 termination due to receipt of a signal. The value 126 was chosen in a similar manner to indicate that the utility could be found, 308 but not invoked. Some scripts produce meaningful error messages differentiating the 126 and 127 cases. The distinction between exit 309 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 310 uses 126 when any attempt to <i>exec</i> the utility fails for any other reason.</p> 311 </blockquote> 312 <h4 class="mansect"><a name="tag_20_152_17" id="tag_20_152_17"></a>EXAMPLES</h4> 313 <blockquote> 314 <ol> 315 <li> 316 <p>The following command combines the output of the parenthesized commands (minus the <apostrophe> characters) onto one line, 317 which is then appended to the file log. It assumes that the expansion of <tt>"$0 $*"</tt> does not include any <apostrophe> 318 or <newline> characters.</p> 319 <pre> 320 <tt>(logname; date; printf "'%s'\n" "$0 $*") | xargs -E "" >>log 321 </tt></pre></li> 322 <li> 323 <p>The following command invokes <a href="../utilities/diff.html"><i>diff</i></a> with successive pairs of arguments originally 324 typed as command line arguments.</p> 325 <pre> 326 <tt>printf "%s\0" "$@" | xargs -0 -n 2 -x diff -- 327 </tt></pre></li> 328 <li> 329 <p>In the following command, the user is asked which regular files below the current directory are to be archived.</p> 330 <pre> 331 <tt>find . -type f -print0 | xargs -0 -p -L 1 ar -r arch 332 </tt></pre></li> 333 <li> 334 <p>The following command invokes <i>command1</i> one or more times with multiple arguments, stopping if an invocation of 335 <i>command1</i> has a non-zero exit status.</p> 336 <pre> 337 <tt>xargs -E "" sh -c 'command1 "$@" || exit 255' sh < xargs_input 338 </tt></pre></li> 339 </ol> 340 </blockquote> 341 <h4 class="mansect"><a name="tag_20_152_18" id="tag_20_152_18"></a>RATIONALE</h4> 342 <blockquote> 343 <p>The <i>xargs</i> utility was usually found only in System V-based systems; BSD systems included an <i>apply</i> utility that 344 provided functionality similar to <i>xargs</i> <b>-n</b> <i>number</i>. The SVID lists <i>xargs</i> as a software development 345 extension. This volume of POSIX.1-2024 does not share the view that it is used only for development, and therefore it is not 346 optional.</p> 347 <p>The classic application of the <i>xargs</i> utility is in conjunction with the <a href="../utilities/find.html"><i>find</i></a> 348 utility to reduce the number of processes launched by a simplistic use of the <a href="../utilities/find.html"><i>find</i></a> 349 <b>-exec</b> combination. The <i>xargs</i> utility is also used to enforce an upper limit on memory required to launch a process. 350 With this basis in mind, this volume of POSIX.1-2024 selected only the minimal features required.</p> 351 <p>Although the 255 exit status is mostly an accident of historical implementations, it allows a utility being used by <i>xargs</i> 352 to tell <i>xargs</i> to terminate if it knows no further invocations using the current data stream shall succeed. Any non-zero exit 353 status from a utility falls into the 1-125 range when <i>xargs</i> exits. There is no statement of how the various non-zero utility 354 exit status codes are accumulated by <i>xargs</i>. The value could be the addition of all codes, their highest value, the last one 355 received, or a single value such as 1. Since no algorithm is arguably better than the others, and since many of the standard 356 utilities say little more (portably) than "pass/fail", no new algorithm was invented.</p> 357 <p>Several other <i>xargs</i> options were removed because simple alternatives already exist within this volume of POSIX.1-2024. 358 For example, the <b>-i</b> <i>replstr</i> option can be just as efficiently performed using a shell <b>for</b> loop. Since 359 <i>xargs</i> calls an <i>exec</i> function with each input line, the <b>-i</b> option does not usually exploit the grouping 360 capabilities of <i>xargs</i>.</p> 361 <p>The requirement that <i>xargs</i> never produces command lines such that invocation of <i>utility</i> is within 2048 bytes of 362 hitting the POSIX <i>exec</i> {ARG_MAX} limitations is intended to guarantee that the invoked utility has room to modify its 363 environment variables and command line arguments and still be able to invoke another utility. Note that the minimum {ARG_MAX} 364 allowed by the System Interfaces volume of POSIX.1-2024 is 4096 bytes and the minimum value allowed by this volume of POSIX.1-2024 365 is 2048 bytes; therefore, the 2048 bytes difference seems reasonable. Note, however, that <i>xargs</i> may never be able to invoke 366 a utility if the environment passed in to <i>xargs</i> comes close to using {ARG_MAX} bytes.</p> 367 <p>The version of <i>xargs</i> required by this volume of POSIX.1-2024 is required to wait for the completion of the invoked 368 command before invoking another command. This was done because historical scripts using <i>xargs</i> assumed sequential execution. 369 Implementations wanting to provide parallel operation of the invoked utilities are encouraged to add an option enabling parallel 370 invocation, but should still wait for termination of all of the children before <i>xargs</i> terminates normally.</p> 371 <p>The <b>-e</b> option was omitted from the ISO POSIX-2:1993 standard in the belief that the <i>eofstr</i> option-argument 372 was recognized only when it was on a line by itself and before quote and escape processing were performed, and that the logical 373 end-of-file processing was only enabled if a <b>-e</b> option was specified. In that case, a simple <a href= 374 "../utilities/sed.html"><i>sed</i></a> script could be used to duplicate the <b>-e</b> functionality. Further investigation 375 revealed that:</p> 376 <ul> 377 <li> 378 <p>The logical end-of-file string was checked for after quote and escape processing, making a <a href= 379 "../utilities/sed.html"><i>sed</i></a> script that provided equivalent functionality much more difficult to write.</p> 380 </li> 381 <li> 382 <p>The default was to perform logical end-of-file processing with an <underscore> as the logical end-of-file string.</p> 383 </li> 384 </ul> 385 <p>To correct this misunderstanding, the <b>-E</b> <i>eofstr</i> option was adopted from the X/Open Portability Guide. Users should 386 note that the description of the <b>-E</b> option matches historical documentation of the <b>-e</b> option (which was not adopted 387 because it did not support the Utility Syntax Guidelines), by saying that if <i>eofstr</i> is the null string, logical end-of-file 388 processing is disabled. Historical implementations of <i>xargs</i> actually did not disable logical end-of-file processing; they 389 treated a null argument found in the input as a logical end-of-file string. (A null <i>string</i> argument could be generated using 390 single or double-quotes (<tt>'"'</tt> or <tt>""</tt>). Since this behavior was not documented historically, it is considered to be 391 a bug.</p> 392 <p>The <b>-I</b>, <b>-L</b>, and <b>-n</b> options are mutually-exclusive. Some implementations use the last one specified if more 393 than one is given on a command line; other implementations treat combinations of the options in different ways.</p> 394 </blockquote> 395 <h4 class="mansect"><a name="tag_20_152_19" id="tag_20_152_19"></a>FUTURE DIRECTIONS</h4> 396 <blockquote> 397 <p>A future version of this standard may require that, when the <b>-0</b> option is specified, if the standard input is not empty 398 and does not end with a null byte, <i>xargs</i> ignores the trailing non-null bytes.</p> 399 </blockquote> 400 <h4 class="mansect"><a name="tag_20_152_20" id="tag_20_152_20"></a>SEE ALSO</h4> 401 <blockquote> 402 <p><a href="../utilities/V3_chap02.html#tag_19"><i>2. Shell Command Language</i></a> , <a href= 403 "../utilities/diff.html#"><i>diff</i></a> , <a href="../utilities/echo.html#"><i>echo</i></a> , <a href= 404 "../utilities/find.html#"><i>find</i></a></p> 405 <p>XBD <a href="../basedefs/V1_chap08.html#tag_08"><i>8. Environment Variables</i></a> , <a href= 406 "../basedefs/V1_chap12.html#tag_12_02"><i>12.2 Utility Syntax Guidelines</i></a></p> 407 <p>XSH <a href="../functions/exec.html#tag_17_129"><i>exec</i></a></p> 408 </blockquote> 409 <h4 class="mansect"><a name="tag_20_152_21" id="tag_20_152_21"></a>CHANGE HISTORY</h4> 410 <blockquote> 411 <p>First released in Issue 2.</p> 412 </blockquote> 413 <h4 class="mansect"><a name="tag_20_152_22" id="tag_20_152_22"></a>Issue 5</h4> 414 <blockquote> 415 <p>A second FUTURE DIRECTION is added.</p> 416 </blockquote> 417 <h4 class="mansect"><a name="tag_20_152_23" id="tag_20_152_23"></a>Issue 6</h4> 418 <blockquote> 419 <p>The obsolescent <b>-e</b>, <b>-i</b>, and <b>-l</b> options are removed.</p> 420 <p>The following new requirements on POSIX implementations derive from alignment with the Single UNIX Specification:</p> 421 <ul> 422 <li> 423 <p>The <b>-p</b> option is added.</p> 424 </li> 425 <li> 426 <p>In the INPUT FILES section, the file <b>/dev/tty</b> is used to read responses required by the <b>-p</b> option.</p> 427 </li> 428 <li> 429 <p>The STDERR section is updated to describe the <b>-p</b> option.</p> 430 </li> 431 </ul> 432 <p>The description of the <b>-E</b> option is aligned with the ISO POSIX-2:1993 standard.</p> 433 <p>The normative text is reworded to avoid use of the term "must" for application requirements.</p> 434 </blockquote> 435 <h4 class="mansect"><a name="tag_20_152_24" id="tag_20_152_24"></a>Issue 7</h4> 436 <blockquote> 437 <p>Austin Group Interpretation 1003.1-2001 #123 is applied, changing the description of the <i>xargs</i> <b>-I</b> option.</p> 438 <p>Austin Group Interpretation 1003.1-2001 #126 is applied, changing the description of the <i>LC_MESSAGES</i> environment 439 variable.</p> 440 <p>SD5-XCU-ERN-68 is applied.</p> 441 <p>SD5-XCU-ERN-97 is applied, updating the SYNOPSIS.</p> 442 <p>SD5-XCU-ERN-128 is applied, clarifying the DESCRIPTION of the logical end-of-file string.</p> 443 <p>SD5-XCU-ERN-132 is applied, updating the EXAMPLES section.</p> 444 <p>POSIX.1-2008, Technical Corrigendum 1, XCU/TC1-2008/0149 [342] is applied.</p> 445 <p>POSIX.1-2008, Technical Corrigendum 2, XCU/TC2-2008/0203 [499] is applied.</p> 446 </blockquote> 447 <h4 class="mansect"><a name="tag_20_152_25" id="tag_20_152_25"></a>Issue 8</h4> 448 <blockquote> 449 <p>Austin Group Defect 243 is applied, adding the <b>-r</b> and <b>-0</b> options.</p> 450 <p>Austin Group Defect 248 is applied, changing the EXAMPLES section.</p> 451 <p>Austin Group Defect 1122 is applied, changing the description of <i>NLSPATH .</i></p> 452 <p>Austin Group Defect 1586 is applied, adding the <a href="../utilities/timeout.html"><i>timeout</i></a> utility.</p> 453 <p>Austin Group Defect 1594 is applied, changing the APPLICATION USAGE section.</p> 454 </blockquote> 455 <div class="box"><em>End of informative text.</em></div> 456 <hr> 457 <p> </p> 458 <a href="#top"><span class="topOfPage">return to top of page</span></a><br> 459 <hr size="2" noshade> 460 <center><font size="2">UNIX® is a registered Trademark of The Open Group.<br> 461 POSIX™ is a Trademark of The IEEE.<br> 462 Copyright © 2001-2024 The IEEE and The Open Group, All Rights Reserved<br> 463 [ <a href="../mindex.html">Main Index</a> | <a href="../basedefs/contents.html">XBD</a> | <a href= 464 "../functions/contents.html">XSH</a> | <a href="../utilities/contents.html">XCU</a> | <a href="../xrat/contents.html">XRAT</a> 465 ]</font></center> 466 <hr size="2" noshade> 467 <div class="NAVHEADER"> 468 <table summary="Header navigation table" class="nav" width="100%" border="0" cellpadding="0" cellspacing="0"> 469 <tr class="nav"> 470 <td class="nav" width="15%" align="left" valign="bottom"><a href="../utilities/write.html" accesskey="P"><<< 471 Previous</a></td> 472 <td class="nav" width="70%" align="center" valign="bottom"><a href="contents.html">Home</a></td> 473 <td class="nav" width="15%" align="right" valign="bottom"><a href="../utilities/xgettext.html" accesskey="N">Next 474 >>></a></td> 475 </tr> 476 </table> 477 <hr align="left" width="100%"></div> 478 </body> 479 </html>