4

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?

Rui F Ribeiro
  • 56,709
  • 26
  • 150
  • 232
Ram Rachum
  • 1,825

1 Answers1

4
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
DopeGhoti
  • 76,081