546 lines
25 KiB
HTML
546 lines
25 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>xargs</title>
|
|
</head>
|
|
<body bgcolor="white">
|
|
<script type="text/javascript" language="JavaScript" src="../jscript/codes.js">
|
|
</script>
|
|
|
|
<basefont size="3"> <a name="xargs"></a> <a name="tag_04_173"></a><!-- xargs -->
|
|
<!--header start-->
|
|
<center><font size="2">The Open Group Base Specifications Issue 6<br>
|
|
IEEE Std 1003.1-2001<br>
|
|
Copyright © 2001 The IEEE and The Open Group, All Rights reserved.</font></center>
|
|
|
|
<!--header end-->
|
|
<hr size="2" noshade>
|
|
<h4><a name="tag_04_173_01"></a>NAME</h4>
|
|
|
|
<blockquote>xargs - construct argument lists and invoke utility</blockquote>
|
|
|
|
<h4><a name="tag_04_173_02"></a>SYNOPSIS</h4>
|
|
|
|
<blockquote class="synopsis">
|
|
<p><code><tt><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> xargs</tt>
|
|
<b>[</b><tt>-t</tt><b>][</b><tt>-p</tt><b>]][</b><tt>-E</tt> <i>eofstr</i><b>]<img src="../images/opt-start.gif" border=
|
|
"0">[</b><tt>-I</tt> <i>replstr</i><b>][</b><tt>-L</tt> <i>number</i><b>]<img src="../images/opt-end.gif" border=
|
|
"0">[</b><tt>-n</tt> <i>number</i> <b>[</b><tt>-x</tt><b>]]<br>
|
|
</b> <tt> </tt> <b>[</b><tt>-s</tt> <i>size</i><b>][</b><i>utility</i>
|
|
<b>[</b><i>argument</i><tt>...</tt><b>]]</b></code></p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_173_03"></a>DESCRIPTION</h4>
|
|
|
|
<blockquote>
|
|
<p>The <i>xargs</i> utility shall construct a command line consisting of the <i>utility</i> and <i>argument</i> operands specified
|
|
followed by as many arguments read in sequence from standard input as fit in length and number constraints specified by the
|
|
options. The <i>xargs</i> utility shall then invoke the constructed command line and wait for its completion. This sequence shall
|
|
be repeated until one of the following occurs:</p>
|
|
|
|
<ul>
|
|
<li>
|
|
<p>An end-of-file condition is detected on standard input.</p>
|
|
</li>
|
|
|
|
<li>
|
|
<p>The logical end-of-file string (see the <b>-E</b> <i>eofstr</i> option) is found on standard input after double-quote
|
|
processing, apostrophe processing, and backslash escape processing (see next paragraph).</p>
|
|
</li>
|
|
|
|
<li>
|
|
<p>An invocation of a constructed command line returns an exit status of 255.</p>
|
|
</li>
|
|
</ul>
|
|
|
|
<p>The application shall ensure that arguments in the standard input are separated by unquoted <blank>s, unescaped
|
|
<blank>s, or <newline>s. A string of zero or more non-double-quote ( <tt>' )'</tt> characters and non- <newline>s
|
|
can be quoted by enclosing them in double-quotes. A string of zero or more non-apostrophe ( <tt>'"</tt> ) characters and non-
|
|
<newline>s can be quoted by enclosing them in apostrophes. Any unquoted character can be escaped by preceding it with a
|
|
backslash. The utility named by <i>utility</i> shall be executed one or more times until the end-of-file is reached or the logical
|
|
end-of file string is found. The results are unspecified if the utility named by <i>utility</i> attempts to read from its standard
|
|
input.</p>
|
|
|
|
<p>The generated command line length shall be the sum of the size in bytes of the utility name and each argument treated as
|
|
strings, including a null byte terminator for each of these strings. The <i>xargs</i> utility shall limit the command line length
|
|
such that when the command line is invoked, the combined argument and environment lists (see the <i>exec</i> family of functions in
|
|
the System Interfaces volume of IEEE Std 1003.1-2001) shall not exceed {ARG_MAX}-2048 bytes. Within this constraint, if
|
|
neither the <b>-n</b> nor the <b>-s</b> option is specified, the default command line length shall be at least {LINE_MAX}.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_173_04"></a>OPTIONS</h4>
|
|
|
|
<blockquote>
|
|
<p>The <i>xargs</i> utility shall conform to the Base Definitions volume of IEEE Std 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>-E </b> <i>eofstr</i></dt>
|
|
|
|
<dd>Use <i>eofstr</i> as the logical end-of-file string. If <b>-E</b> is not specified, it is unspecified whether the logical
|
|
end-of-file string is the underscore character ( <tt>'_'</tt> ) or the end-of-file string capability is disabled. When
|
|
<i>eofstr</i> is the null string, the logical end-of-file string capability shall be disabled and underscore characters shall be
|
|
taken literally.</dd>
|
|
|
|
<dt><b>-I </b> <i>replstr</i></dt>
|
|
|
|
<dd><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">
|
|
Insert mode: <i>utility</i> is executed for each line from standard input, taking the entire line as a single argument, inserting
|
|
it in <i>argument</i>s for each occurrence of <i>replstr</i>. A maximum of five arguments in <i>argument</i>s can each contain one
|
|
or more instances of <i>replstr</i>. Any <blank>s at the beginning of each line shall be ignored. Constructed arguments
|
|
cannot grow larger than 255 bytes. Option <b>-x</b> shall be forced on. <img src="../images/opt-end.gif" alt="[Option End]" border=
|
|
"0"></dd>
|
|
|
|
<dt><b>-L </b> <i>number</i></dt>
|
|
|
|
<dd><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">
|
|
The <i>utility</i> shall be executed for each non-empty <i>number</i> lines of arguments from standard input. The last invocation
|
|
of <i>utility</i> shall be with fewer lines of arguments if fewer than <i>number</i> remain. A line is considered to end with the
|
|
first <newline> unless the last character of the line is a <blank>; a trailing <blank> signals continuation to
|
|
the next non-empty line, inclusive. The <b>-L</b> and <b>-n</b> options are mutually-exclusive; the last one specified shall take
|
|
effect. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></dd>
|
|
|
|
<dt><b>-n </b> <i>number</i></dt>
|
|
|
|
<dd>Invoke <i>utility</i> using as many standard input arguments as possible, up to <i>number</i> (a positive decimal integer)
|
|
arguments maximum. Fewer arguments shall be used if:
|
|
|
|
<ul>
|
|
<li>
|
|
<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>
|
|
option).</p>
|
|
</li>
|
|
|
|
<li>
|
|
<p>The last iteration has fewer than <i>number</i>, but not zero, operands remaining.</p>
|
|
</li>
|
|
</ul>
|
|
</dd>
|
|
|
|
<dt><b>-p</b></dt>
|
|
|
|
<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
|
|
write the command instance to be executed, followed by a prompt to standard error. An affirmative response read from
|
|
<b>/dev/tty</b> shall execute the command; otherwise, that particular invocation of <i>utility</i> shall be skipped.</dd>
|
|
|
|
<dt><b>-s </b> <i>size</i></dt>
|
|
|
|
<dd>Invoke <i>utility</i> using as many standard input arguments as possible yielding a command line length less than <i>size</i>
|
|
(a positive decimal integer) bytes. Fewer arguments shall be used if:
|
|
|
|
<ul>
|
|
<li>
|
|
<p>The total number of arguments exceeds that specified by the <b>-n</b> option.</p>
|
|
</li>
|
|
|
|
<li>
|
|
<p><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">
|
|
The total number of lines exceeds that specified by the <b>-L</b> option. <img src="../images/opt-end.gif" alt="[Option End]"
|
|
border="0"></p>
|
|
</li>
|
|
|
|
<li>
|
|
<p>End-of-file is encountered on standard input before <i>size</i> bytes are accumulated.</p>
|
|
</li>
|
|
</ul>
|
|
|
|
<p>Values of <i>size</i> up to at least {LINE_MAX} bytes shall be supported, provided that the constraints specified in the
|
|
DESCRIPTION are met. It shall not be considered an error if a value larger than that supported by the implementation or exceeding
|
|
the constraints specified in the DESCRIPTION is given; <i>xargs</i> shall use the largest value it supports within the
|
|
constraints.</p>
|
|
</dd>
|
|
|
|
<dt><b>-t</b></dt>
|
|
|
|
<dd>Enable trace mode. Each generated command line shall be written to standard error just prior to invocation.</dd>
|
|
|
|
<dt><b>-x</b></dt>
|
|
|
|
<dd>Terminate if a command line containing <i>number</i> arguments (see the <b>-n</b> option above) <sup>[<a href=
|
|
"javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0"> or
|
|
<i>number</i> lines (see the <b>-L</b> option above) <img src="../images/opt-end.gif" alt="[Option End]" border="0"> will not fit
|
|
in the implied or specified size (see the <b>-s</b> option above).</dd>
|
|
</dl>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_173_05"></a>OPERANDS</h4>
|
|
|
|
<blockquote>
|
|
<p>The following operands shall be supported:</p>
|
|
|
|
<dl compact>
|
|
<dt><i>utility</i></dt>
|
|
|
|
<dd>The name of the utility to be invoked, found by search path using the <i>PATH</i> environment variable, described in the Base
|
|
Definitions volume of IEEE Std 1003.1-2001, <a href="../basedefs/xbd_chap08.html">Chapter 8, Environment Variables</a>.
|
|
If <i>utility</i> is omitted, the default shall 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 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>An initial option or operand for the invocation of <i>utility</i>.</dd>
|
|
</dl>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_173_06"></a>STDIN</h4>
|
|
|
|
<blockquote>
|
|
<p>The standard input shall be a text file. The results are unspecified if an end-of-file condition is detected immediately
|
|
following an escaped <newline>.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_173_07"></a>INPUT FILES</h4>
|
|
|
|
<blockquote>
|
|
<p>The file <b>/dev/tty</b> shall be used to read responses required by the <b>-p</b> option.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_173_08"></a>ENVIRONMENT VARIABLES</h4>
|
|
|
|
<blockquote>
|
|
<p>The following environment variables shall affect the execution of <i>xargs</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 Std 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_COLLATE</i></dt>
|
|
|
|
<dd><br>
|
|
Determine the locale for the behavior of ranges, equivalence classes, and multi-character collating elements used in the extended
|
|
regular expression defined for the <b>yesexpr</b> locale keyword in the <i>LC_MESSAGES</i> category.</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 and input files) and the behavior of character classes used in the extended regular
|
|
expression defined for the <b>yesexpr</b> locale keyword in the <i>LC_MESSAGES</i> category.</dd>
|
|
|
|
<dt><i>LC_MESSAGES</i></dt>
|
|
|
|
<dd>Determine the locale for the processing of affirmative responses and 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 <i>utility</i>, as described in the Base Definitions volume of IEEE Std 1003.1-2001, <a
|
|
href="../basedefs/xbd_chap08.html">Chapter 8, Environment Variables</a>.</dd>
|
|
</dl>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_173_09"></a>ASYNCHRONOUS EVENTS</h4>
|
|
|
|
<blockquote>
|
|
<p>Default.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_173_10"></a>STDOUT</h4>
|
|
|
|
<blockquote>
|
|
<p>Not used.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_173_11"></a>STDERR</h4>
|
|
|
|
<blockquote>
|
|
<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
|
|
specified, the <i>utility</i> and its constructed argument list shall be written to standard error, as it will be invoked, prior to
|
|
invocation. If <b>-p</b> is specified, a prompt of the following format shall be written (in the POSIX locale):</p>
|
|
|
|
<pre>
|
|
<tt>"?..."
|
|
</tt>
|
|
</pre>
|
|
|
|
<p>at the end of the line of the output from <b>-t</b>.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_173_12"></a>OUTPUT FILES</h4>
|
|
|
|
<blockquote>
|
|
<p>None.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_173_13"></a>EXTENDED DESCRIPTION</h4>
|
|
|
|
<blockquote>
|
|
<p>None.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_173_14"></a>EXIT STATUS</h4>
|
|
|
|
<blockquote>
|
|
<p>The following exit values shall be returned:</p>
|
|
|
|
<dl compact>
|
|
<dt> 0</dt>
|
|
|
|
<dd>All invocations of <i>utility</i> returned exit status zero.</dd>
|
|
|
|
<dt>1-125</dt>
|
|
|
|
<dd>A command line meeting the specified requirements could not be assembled, one or more of the invocations of <i>utility</i>
|
|
returned a non-zero exit status, or some other error occurred.</dd>
|
|
|
|
<dt> 126</dt>
|
|
|
|
<dd>The utility specified by <i>utility</i> was found but could not be invoked.</dd>
|
|
|
|
<dt> 127</dt>
|
|
|
|
<dd>The utility specified by <i>utility</i> could not be found.</dd>
|
|
</dl>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_173_15"></a>CONSEQUENCES OF ERRORS</h4>
|
|
|
|
<blockquote>
|
|
<p>If a command line meeting the specified requirements cannot be assembled, the utility cannot be invoked, an invocation of the
|
|
utility is terminated by a signal, or an invocation of the utility exits with exit status 255, the <i>xargs</i> utility shall write
|
|
a diagnostic message and exit without processing any remaining input.</p>
|
|
</blockquote>
|
|
|
|
<hr>
|
|
<div class="box"><em>The following sections are informative.</em></div>
|
|
|
|
<h4><a name="tag_04_173_16"></a>APPLICATION USAGE</h4>
|
|
|
|
<blockquote>
|
|
<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
|
|
invocations using the current data stream will succeed. Thus, <i>utility</i> should explicitly <a href=
|
|
"../utilities/exit.html"><i>exit</i></a> with an appropriate value to avoid accidentally returning with 255.</p>
|
|
|
|
<p>Note that input is parsed as lines; <blank>s separate arguments. If <i>xargs</i> is used to bundle output of commands like
|
|
<a href="../utilities/find.html"><i>find</i></a> <i>dir</i> <b>-print</b> or <a href="../utilities/ls.html"><i>ls</i></a> into
|
|
commands to be executed, unexpected results are likely if any filenames contain any <blank>s or <newline>s. This can be
|
|
fixed by using <a href="../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 <i>xargs</i>. Note that the quoting rules used by <i>xargs</i> are not the same as in the shell. They were
|
|
not made consistent here because existing applications depend on the current rules and the shell syntax is not fully compatible
|
|
with it. An easy rule that can be used to transform any string into a quoted form that <i>xargs</i> interprets correctly is to
|
|
precede each character in the string with a backslash.</p>
|
|
|
|
<p>On implementations with a large value for {ARG_MAX}, <i>xargs</i> may produce command lines longer than {LINE_MAX}. For
|
|
invocation of utilities, this is not a problem. If <i>xargs</i> is being used to create a text file, users should explicitly set
|
|
the maximum command line length with the <b>-s</b> option.</p>
|
|
|
|
<p>The <a href="../utilities/command.html"><i>command</i></a>, <a href="../utilities/env.html"><i>env</i></a>, <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 <i>xargs</i> 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
|
|
<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>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_173_17"></a>EXAMPLES</h4>
|
|
|
|
<blockquote>
|
|
<ol>
|
|
<li>
|
|
<p>The following command combines the output of the parenthesised commands onto one line, which is then written to the end-of-file
|
|
<b>log</b>:</p>
|
|
|
|
<pre>
|
|
<tt>(logname; date; printf "%s\n" "$0 $*") | xargs >>log
|
|
</tt>
|
|
</pre>
|
|
</li>
|
|
|
|
<li>
|
|
<p>The following command invokes <a href="../utilities/diff.html"><i>diff</i></a> with successive pairs of arguments originally
|
|
typed as command line arguments (assuming there are no embedded <blank>s in the elements of the original argument list):</p>
|
|
|
|
<pre>
|
|
<tt>printf "%s\n" "$*" | xargs -n 2 -x diff
|
|
</tt>
|
|
</pre>
|
|
</li>
|
|
|
|
<li>
|
|
<p>In the following commands, the user is asked which files in the current directory are to be archived. The files are archived
|
|
into <b>arch</b>; <i>a</i>, one at a time, or <i>b</i>, many at a time.</p>
|
|
|
|
<pre>
|
|
<tt>a. ls | xargs -p -L 1 ar -r arch
|
|
<br>
|
|
b. ls | xargs -p -L 1 | xargs ar -r arch
|
|
</tt>
|
|
</pre>
|
|
</li>
|
|
|
|
<li>
|
|
<p>The following executes with successive pairs of arguments originally typed as command line arguments:</p>
|
|
|
|
<pre>
|
|
<tt>echo $* | xargs -n 2 diff
|
|
</tt>
|
|
</pre>
|
|
</li>
|
|
|
|
<li>
|
|
<p>On XSI-conformant systems, the following moves all files from directory <b>$1</b> to directory <b>$2</b>, and echoes each move
|
|
command just before doing it:</p>
|
|
|
|
<pre>
|
|
<tt>ls $1 | xargs -I {} -t mv $1/{} $2/{}
|
|
</tt>
|
|
</pre>
|
|
</li>
|
|
</ol>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_173_18"></a>RATIONALE</h4>
|
|
|
|
<blockquote>
|
|
<p>The <i>xargs</i> utility was usually found only in System V-based systems; BSD systems included an <i>apply</i> utility that
|
|
provided functionality similar to <i>xargs</i> <b>-n</b> <i>number</i>. The SVID lists <i>xargs</i> as a software development
|
|
extension. This volume of IEEE Std 1003.1-2001 does not share the view that it is used only for development, and
|
|
therefore it is not optional.</p>
|
|
|
|
<p>The classic application of the <i>xargs</i> utility is in conjunction with the <a href="../utilities/find.html"><i>find</i></a>
|
|
utility to reduce the number of processes launched by a simplistic use of the <a href="../utilities/find.html"><i>find</i></a>
|
|
<b>-exec</b> combination. The <i>xargs</i> utility is also used to enforce an upper limit on memory required to launch a process.
|
|
With this basis in mind, this volume of IEEE Std 1003.1-2001 selected only the minimal features required.</p>
|
|
|
|
<p>Although the 255 exit status is mostly an accident of historical implementations, it allows a utility being used by <i>xargs</i>
|
|
to tell <i>xargs</i> to terminate if it knows no further invocations using the current data stream shall succeed. Any non-zero exit
|
|
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
|
|
exit status codes are accumulated by <i>xargs</i>. The value could be the addition of all codes, their highest value, the last one
|
|
received, or a single value such as 1. Since no algorithm is arguably better than the others, and since many of the standard
|
|
utilities say little more (portably) than "pass/fail", no new algorithm was invented.</p>
|
|
|
|
<p>Several other <i>xargs</i> options were withdrawn because simple alternatives already exist within this volume of
|
|
IEEE Std 1003.1-2001. For example, the <b>-i</b> <i>replstr</i> option can be just as efficiently performed using a shell
|
|
<b>for</b> loop. Since <i>xargs</i> calls an <i>exec</i> function with each input line, the <b>-i</b> option does not usually
|
|
exploit the grouping capabilities of <i>xargs</i>.</p>
|
|
|
|
<p>The requirement that <i>xargs</i> never produces command lines such that invocation of <i>utility</i> is within 2048 bytes of
|
|
hitting the POSIX <i>exec</i> {ARG_MAX} limitations is intended to guarantee that the invoked utility has room to modify its
|
|
environment variables and command line arguments and still be able to invoke another utility. Note that the minimum {ARG_MAX}
|
|
allowed by the System Interfaces volume of IEEE Std 1003.1-2001 is 4096 bytes and the minimum value allowed by this
|
|
volume of IEEE Std 1003.1-2001 is 2048 bytes; therefore, the 2048 bytes difference seems reasonable. Note, however, that
|
|
<i>xargs</i> may never be able to invoke a utility if the environment passed in to <i>xargs</i> comes close to using {ARG_MAX}
|
|
bytes.</p>
|
|
|
|
<p>The version of <i>xargs</i> required by this volume of IEEE Std 1003.1-2001 is required to wait for the completion of
|
|
the invoked command before invoking another command. This was done because historical scripts using <i>xargs</i> assumed sequential
|
|
execution. Implementations wanting to provide parallel operation of the invoked utilities are encouraged to add an option enabling
|
|
parallel invocation, but should still wait for termination of all of the children before <i>xargs</i> terminates normally.</p>
|
|
|
|
<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
|
|
was recognized only when it was on a line by itself and before quote and escape processing were performed, and that the logical
|
|
end-of-file processing was only enabled if a <b>-e</b> option was specified. In that case, a simple <a href=
|
|
"../utilities/sed.html"><i>sed</i></a> script could be used to duplicate the <b>-e</b> functionality. Further investigation
|
|
revealed that:</p>
|
|
|
|
<ul>
|
|
<li>
|
|
<p>The logical end-of-file string was checked for after quote and escape processing, making a <a href=
|
|
"../utilities/sed.html"><i>sed</i></a> script that provided equivalent functionality much more difficult to write.</p>
|
|
</li>
|
|
|
|
<li>
|
|
<p>The default was to perform logical end-of-file processing with an underscore as the logical end-of-file string.</p>
|
|
</li>
|
|
</ul>
|
|
|
|
<p>To correct this misunderstanding, the <b>-E</b> <i>eofstr</i> option was adopted from the X/Open Portability Guide. Users should
|
|
note that the description of the <b>-E</b> option matches historical documentation of the <b>-e</b> option (which was not adopted
|
|
because it did not support the Utility Syntax Guidelines), by saying that if <i>eofstr</i> is the null string, logical end-of-file
|
|
processing is disabled. Historical implementations of <i>xargs</i> actually did not disable logical end-of-file processing; they
|
|
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
|
|
single or double quotes ( <tt>''</tt> or <tt>""</tt> ). Since this behavior was not documented historically, it is considered to be
|
|
a bug.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_173_19"></a>FUTURE DIRECTIONS</h4>
|
|
|
|
<blockquote>
|
|
<p>None.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_173_20"></a>SEE ALSO</h4>
|
|
|
|
<blockquote>
|
|
<p><a href="xcu_chap02.html#tag_02"><i>Shell Command Language</i></a> , <a href="echo.html"><i>echo</i></a> , <a href=
|
|
"find.html"><i>find</i></a> , the System Interfaces volume of IEEE Std 1003.1-2001, <i>exec</i></p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_173_21"></a>CHANGE HISTORY</h4>
|
|
|
|
<blockquote>
|
|
<p>First released in Issue 2.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_173_22"></a>Issue 5</h4>
|
|
|
|
<blockquote>
|
|
<p>A second FUTURE DIRECTION is added.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_173_23"></a>Issue 6</h4>
|
|
|
|
<blockquote>
|
|
<p>The obsolescent <b>-e</b>, <b>-i</b>, and <b>-l</b> options are removed.</p>
|
|
|
|
<p>The following new requirements on POSIX implementations derive from alignment with the Single UNIX Specification:</p>
|
|
|
|
<ul>
|
|
<li>
|
|
<p>The <b>-p</b> option is added.</p>
|
|
</li>
|
|
|
|
<li>
|
|
<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>
|
|
</li>
|
|
|
|
<li>
|
|
<p>The STDERR section is updated to describe the <b>-p</b> option.</p>
|
|
</li>
|
|
</ul>
|
|
|
|
<p>The description of the <b>-E</b> option is aligned with the ISO POSIX-2:1993 standard.</p>
|
|
|
|
<p>The normative text is reworded to avoid use of the term "must" for application requirements.</p>
|
|
</blockquote>
|
|
|
|
<div class="box"><em>End of informative text.</em></div>
|
|
|
|
<hr>
|
|
<hr size="2" noshade>
|
|
<center><font size="2"><!--footer start-->
|
|
UNIX ® is a registered Trademark of The Open Group.<br>
|
|
POSIX ® 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>
|
|
|