title: How can I run the body of the for loop parallely in bash
body: <p>I have 4 commands that are all dependent on each other within the body of a nested for loop (Hence they should be executed sequentially). I would like to speed up the execution time, so I was thinking to run those 4 commands parallely with the next 4 commands and so on. I have read that the <code>&amp;</code> and <code>wait</code> should be used in this case. However, I am not exactly sure where to place them since placing them after each of the 4 command won't speed up anything as far as I understand.</p>
  <p>I have around 10 cores to use.</p>
  <pre><code>for p in {50,60,70,80,90,100,200,300}
  do      
    for min_p_len in {1,2,3,4,5}
    do      
      for min_s_rem in {1,2,3}
      do 
        for length_threshold in {2,3,4}
        do
          command 1
          command 2
          command 3
          command 4
        done
      done    
    done         
  done
  </code></pre>