echo foo | xargs -L 1 -I '{}' echo '{}'
foo
echo foo | xargs -I '{}' -L 1 echo '{}'
{} foo
Why changing the order of options of xargs changes the output?
Version: xargs (GNU findutils) 4.6.0
When options given to xargs conflict, order may matter.
IEEE Std 1003.1-2008, 2016 Edition/Open Group Base Specifications Issue 7 added the following text1 to the specification of xargs:
The -I, -L, and -n options are mutually-exclusive. Some implementations use the last one specified if more than one is given on a command line; other implementations treat combinations of the options in different ways.
This codifies the behavior of many implementations of xargs, going back to the original version in PWB/Unix, whose man page says
When there are flag conflicts (e.g., -l vs. -n), the last flag has precedence.
In the GNU version of xargs, -L
disables any previous -I
option. So in your second example,
echo foo | xargs -I '{}' -L 1 echo '{}'
{}
is just an ordinary argument passed to echo
, with no substitution being done.
[1]Compared to IEEE Std 1003.1, 2004 Edition/Open Group Base Specifications Issue 6.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments