Wait for all jobs and return the exit code of the last failing job. Unlike solutions above, this does not require pid saving, or modifying inner loops of scripts. Just bg away, and wait.
function wait_ex { # this waits for all jobs and returns the exit code of the last failing job ecode=0 while true; do wait[ -n z "$(jobs)" ] && break err="$?" wait -n [ "$err" == "127" ] && breakerr="$?" [ "$err" != "0" ] && ecode="$err" done return $ecode } EDIT: Fixed the bug where this could be fooled by a script that ran a command that didn't exist.