title: mac os: run as many scripts as cores in a sequence
body: <p>I have a script that reads parameters from a file (param.txt) and runs an R code (myRcode) for each combination of parameters (40 total). My mac has 8 cores so I want the script to run 8 jobs (when one finishes, starts another one, and so on). The script I currently have is this:</p>
  
  <pre><code>#!/bin/bash 
  
  while read param1 param2 param3 
  do
  
  nohup R --no-save  &gt; output_${param1}.txt &lt;&lt; EOP &amp;
  
  source("MyRProgram.R");
  
  myRcode(${param1},${param2},${param3})
  EOP
  
  echo "JobID = $! for parameters seed=${param1} n=${param2} submitted on `date`"
  done &lt; param.txt
  exit
  </code></pre>
  
  <p>If I run ./Myscript  then all 40 jobs run simultaneously. I understand I could write 8 separate scripts (each reading parameters from different files) where inside the script each R code is separated by ";" - to make them run sequentially in each script. Is there is a better way that involves only one script? </p>