Skip to main content
1 of 5
Alexander Mills
  • 10.9k
  • 27
  • 120
  • 214

As usual bash is HELLA crazy; I would not F with this unless I had to.

this is the generic script you're looking for. The only downside is your commands are in quotes which means syntax highlighting via your IDE will not really work.

    #!/usr/bin/env bash
    
    arr=()  # holds PIDs
    
    commands=(
        "echo 'hallelujah'; exit 1;"
        "echo 'marzipan'; exit 2;"
    )
    
    commands_len="${#commands[@]}"  # get length of commands
    clen=`expr ${commands_len} - 1`  # subtract one from length
    
    
    for i in `seq 0 "$clen"`
    do
       # run the command via bash in subshell and push PID to array
       (echo "${commands[$i]}" | bash) & arr+=($!)  
    done
    
    len="${#arr[@]}"  # get length of arr
    
    
    EXIT_CODE=0;  # exit code of overall script
    
    for i in `seq 0 "$len"`
    do
        pid="${arr[$i]}";
        wait ${pid} ; CODE="$?"
        if [[ ${CODE} > 0 ]]; then
           echo "at least one test failed";
          EXIT_CODE=1;
          fi
    done
    
    echo "EXIT_CODE => $EXIT_CODE"
    exit "$EXIT_CODE"

    # end

thanks to @michael homer for getting me on the right track

Alexander Mills
  • 10.9k
  • 27
  • 120
  • 214