I'm trying to use xargs to run a command for each provided argument, but unfortunately the --replace/-I flag doesn't seem to work properly when conjugated with -n. It seems that {} will expand into the full list of arguments read from stdin, regardless of the -n option.
Unfortunately all of the examples on the web seem to be for commands (mv, cp, rm) which will take multiple arguments where {} is expanded.
For example, when running:
echo a b c d | xargs -n 1 -I {} echo derp {}
The output is:
derp a b c d
But I expected:
derp a
derp b
derp c
derp d
However, running it without -I {} yields the expected result:
echo a b c d | xargs -n 1 echo derp
derp a
derp b
derp c
derp d
Is there any way to achieve this with xargs? My ultimate intention is to use it to run multiple (parralel) ssh sessions, like
echo server{1..90} | xargs -n 1 -P 0 -I {} ssh {} 'echo $SOME_HOST_INFO'
I'm running xargs (GNU findutils) 4.4.2
on RHEL 6.3.
xargs
, but not GNUxargs
.man xargs
on-I
:Also, unquoted blanks do not terminate input items; instead the separator is the newline character. Implies -x and -L 1.
So it behaves as designed.