Execute multiple commands in background and evaluate their return codes

#!/bin/bash
/bin/false &
PID1=$!
/bin/true &
PID2=$!
wait $PID1
RET1=$?
wait $PID2
RET2=$?
if [ $RET1 == 0 ] && [ $RET2 == 0 ]; then
echo succeeded
exit 0
else
echo failed
exit 1
fi

source

Leave a Reply