3

This question already has an answer here:

I think that xargs is intended exactly for this, but I tried using it and couldn't figure it out.

I have a command foo -bar 123 --baz=whatever. I want a Bash one-liner to run three copies of it in parallel, except they will have a different argument for 123. Say the first copy will be 123, the second one is 234 and the third one is 345. I want the three commands to execute in parallel.

How can I do this?

marked as duplicate by Stephen Kitt, Rui F Ribeiro, Jeff Schaller, HalosGhost, countermode Nov 23 '16 at 23:26

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

3
for arg in 123 234 345; do 
    foo -bar "$arg" --baz=quux &
done

Alternatively:

echo 123 234 345 | xargs -P3 -n1 -J% foo -bar % --baz=quux

Not the answer you're looking for? Browse other questions tagged or ask your own question.