Skip to main content
edited tags
Link
Jeff Schaller
  • 68.8k
  • 35
  • 122
  • 267
Source Link

make a loop parallel

How to make this loop parallel :

for a in $(seq 1 3)
do
  for b in 0.1 0.2 
  do
    echo process with a=$a and b=$b &
  done
done

is it in parallel or not ? In fact, I want to run the instruction echo process with a=$a and b=$b in parallel for each combination of the values a and b Here is the result of runing the above shell :

process with a=1 and b=0.1
process with a=2 and b=0.2
process with a=2 and b=0.1
process with a=3 and b=0.2
process with a=3 and b=0.1
process with a=1 and b=0.2

Thanks.