I want to run some scripts in parallel and if all succeeds I will execute some extra commands. However if any of the subshells fails I want to exit immediately.
I guess it is easier to explain with an example:
exit_in_1() {
sleep 1
echo "This should be the last thing printed"
exit 1
}
exit_in_2() {
sleep 2
echo "This should not be printed"
exit 1
}
exit_in_1 &
exit_in_2 &
echo "This should be printed immediately"
sleep 3
echo "This should not be printed also"
Above script prints all the echos.