I have a bash script running two subscripts t1 and t2. Both t1 and t2 are background processes and t1 will raise an error. How do I catch this error and exit the whole script completely?
#!/bin/bash
set -e
error1() {
echo "exit whole script!!!"
exit 1
}
# this script will rise an error
./t1.sh &
pid1=$!
./t2.sh &
pid2=$!
wait $pid2
if [ $pid2 -eq 0 ]; then
trap 'error1' ERR
fi
wait $pid1
if [ $pid1 -eq 0 ]; then
trap 'error1' ERR
fi