How to wait in a bash script for several subprocesses spawned from that script to finish, and then return exit code !=0 when any of the subprocesses ends with code !=0? Simple script: #!/bin/bash for i in `seq 0 9`; do calculations $i & done wait The above script will wait for all 10 spawned subprocesses, but it will always give the exit status 0 (see help wait). How can I modify this script so it