создавать списки аргументов и вызывать утилиту (construct argument lists and invoke utility)
Использование в приложениях (Application usage)
The 255 exit status allows a utility being used by xargs to tell
xargs to terminate if it knows no further invocations using the
current data stream will succeed. Thus, utility should explicitly
exit with an appropriate value to avoid accidentally returning
with 255.
Note that since input is parsed as lines, <blank> characters
separate arguments, and <backslash>, <apostrophe>, and double-
quote characters are used for quoting, if xargs is used to bundle
the output of commands like find dir -print
or ls into commands
to be executed, unexpected results are likely if any filenames
contain <blank>, <newline>, or quoting characters. This can be
solved by using find to call a script that converts each file
found into a quoted string that is then piped to xargs, but in
most cases it is preferable just to have find do the argument
aggregation itself by using -exec
with a '+'
terminator instead
of ';'
. Note that the quoting rules used by xargs are not the
same as in the shell. They were not made consistent here because
existing applications depend on the current rules. An easy (but
inefficient) method that can be used to transform input
consisting of one argument per line into a quoted form that xargs
interprets correctly is to precede each non-<newline> character
with a <backslash>. More efficient alternatives are shown in
Example 2 and Example 5 below.
On implementations with a large value for {ARG_MAX}, xargs may
produce command lines longer than {LINE_MAX}. For invocation of
utilities, this is not a problem. If xargs is being used to
create a text file, users should explicitly set the maximum
command line length with the -s
option.
The command, env, nice, nohup, time, and xargs 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 exec the utility fail with [ENOENT]
, and
uses 126 when any attempt to exec the utility fails for any other
reason.