title: How do I execute multiple commands in parallel on an array of parameters with bash, and fail if at least one of them failed
body: <p>I have a bash script with a function that needs to run in parallel with different arguments.
  I need to know if at least one of the executions failed (returned non-zero) - doesn't matter how many failed.</p>
  
  <p>The command accepts an array of parameters for the execution. 
  I need to limit the concurrency to 4 concurrent runs due to high load.
  I also need to print the logs in the parent process (the one that runs the bash script)</p>
  
  <p>this is the function I'm running:</p>
  
  <pre><code>function run_and_retry {
    EXIT_STATUS=0
    $COMMAND || EXIT_STATUS=$?
  
    if [ $EXIT_STATUS -ne 0 ]; then
      EXIT_STATUS=0
      $COMMAND || EXIT_STATUS=$?
  
    fi
  
    return $EXIT_STATUS
  }
  </code></pre>
  
  <p>I've tried using GNU parallel and xargs and encountered issues with both. </p>
  
  <p>With xargs: (couldn't get the exit status out of it, and it also didn't work when I ran it in TravisCI)</p>
  
  <pre><code>PARAMETERS=(first-parameter second-parameter third-parameter)
  export -f run_and_retry
  echo "${PARAMETERS[@]}" | xargs -P 4 -n 1 -I {} bash -c "run_and_retry {}"
  </code></pre>
  
  <p>With GNU parallel:</p>
  
  <pre><code>PARAMETERS=(first-parameter second-parameter third-parameter)
  export -f run_and_retry
  parallel -j 4 -k --lb 2 run_and_retry {} ::: echo "${PARAMETERS[@]}" 
  </code></pre>