I want to do the following things:
Execute multiple shell scripts (here 2 scripts) concurrently.
Wait until both scripts finish
If you have GNU Parallel http://www.gnu.org/software/parallel/ installed you can do this:
parallel -j0 '{}; echo $?' ::: a.sh b.sh
I have a suspicion that you want the exit code to check if one of them failed, and that you actually do not care what the precise exit code was. In that case you can do:
parallel -j0 ::: a.sh b.sh || echo one or both of them failed
If it is sufficient to get the error code of the last that failed:
parallel -j0 --halt 1 ::: a.sh b.sh; echo $?
Maybe you would like to kill a.sh if b.sh finishes early but fails:
parallel -j0 --halt 2 ::: a.sh b.sh; echo $?
You can install GNU Parallel simply by:
$ (wget -O - pi.dk/3 || lynx -source pi.dk/3 || curl pi.dk/3/ || \
fetch -o - http://pi.dk/3 ) > install.sh
$ sha1sum install.sh | grep 67bd7bc7dc20aff99eb8f1266574dadb
12345678 67bd7bc7 dc20aff9 9eb8f126 6574dadb
$ md5sum install.sh | grep b7a15cdbb07fb6e11b0338577bc1780f
b7a15cdb b07fb6e1 1b033857 7bc1780f
$ sha512sum install.sh | grep 186000b62b66969d7506ca4f885e0c80e02a22444
6f25960b d4b90cf6 ba5b76de c1acdf39 f3d24249 72930394 a4164351 93a7668d
21ff9839 6f920be5 186000b6 2b66969d 7506ca4f 885e0c80 e02a2244 40e8a43f
$ bash install.sh
Watch the intro videos for GNU Parallel to learn more: https://www.youtube.com/playlist?list=PL284C9FF2488BC6D1
Print the cheat sheet: https://www.gnu.org/software/parallel/parallel_cheat.pdf