Issue
I try this command:
echo tony mary | xargs -i -n1 echo "{} said: hello"
I think that xargs's default delimiter is blank characters including whitespace, tabs and newlines. So I think the output of echo should be split into tony
and mary
. And because I add the option -n1
, I expected it to output
tony said: hello
mary said: hello
Instead, it outputs:
tony mary said: hello
Why?
Solution
You need newline delimited input:
$ printf '%s\n' tony mary | xargs -i -n1 echo "{} said: hello"
tony said: hello
mary said: hello
This option is now deprecated, instead prefer the use of:
xargs -I{} ...
Answered By - Gilles Quénot Answer Checked By - Marie Seifert (WPSolving Admin)