xargs: Does order of options matter?

Cyker

Input 0

echo foo | xargs -L 1 -I '{}' echo '{}'

Output 0

foo

Input 1

echo foo | xargs -I '{}' -L 1 echo '{}'

Output 1

{} foo

Why changing the order of options of xargs changes the output?

Version: xargs (GNU findutils) 4.6.0

Mark Plotnick

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Does the order of command options in linux matter?

From Dev

Spring Security java config - why does order of options matter?

From Java

Does annotations order matter?

From Dev

Does order of conditions in $and matter?

From Dev

SQL - does order of OR conditions matter?

From Java

Does the order of members in a struct matter?

From Dev

Does the order of natural joins matter

From Dev

Does the order of subscribeOn and observeOn matter?

From Dev

Does Python import order matter

From Dev

Does variable order matter for sscanf?

From Dev

Does the order of a Java class matter?

From Dev

Prolog Does the order of recursion matter?

From Dev

Does parameter order matter with tar?

From Dev

Prolog Does the order of recursion matter?

From Dev

Does the order of rules in ABNF matter?

From Dev

.zshrc configuration, does order matter?

From Dev

Does the order of header properties matter?

From Dev

Does the order of constraints in a pred matter?

From Dev

Does order of html meta tags matter?

From Dev

Does the order of partitioned columns in WHERE clause matter

From Dev

Does the order of Babel 6 presets matter?

From Dev

Does class/function order matter in C++?

From Dev

Why does the order of css selectors matter?

From Dev

Boolean equal: 0 == a, does operand order matter?

From Dev

Does order of inheritance between class and interface matter?

From Dev

Does the order in which dynamic libraries are loaded matter?

From Java

Why does order of mutable borrows matter in Rust?

From Dev

Why does declaration order matter for generic members?

From Dev

Does the order of implicit parameters matter in Scala?

Related Related

HotTag

Archive