xargs with multiple arguments

Howard picture Howard · Sep 22, 2010 · Viewed 77.6k times · Source

I have a source input, input.txt

a.txt
b.txt
c.txt

I want to feed these input into a program as the following:

my-program --file=a.txt --file=b.txt --file=c.txt

So I try to use xargs, but with no luck.

cat input.txt | xargs -i echo "my-program --file"{}

It gives

my-program --file=a.txt
my-program --file=b.txt
my-program --file=c.txt

But I want

my-program --file=a.txt --file=b.txt --file=c.txt

Any idea?

Answer

sauliux picture sauliux · Sep 2, 2014

dont listen to all of them :) just look at this example:

echo argument1 argument2 argument3 | xargs -l bash -c 'echo this is first:$0 second:$1 third:$2' | xargs

output will be

this is first:argument1 second:argument2 third:argument3