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?

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


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.