Execute multiple commands in background and evaluate their return codes


/ Published in: Bash
Save to your folder(s)

Execute multiple commands in background, wait for each to be finished and evaluate their return codes.


Copy this code and paste it in your HTML
  1. #!/bin/bash
  2. /bin/false &
  3. PID1=$!
  4. /bin/true &
  5. PID2=$!
  6. wait $PID1
  7. RET1=$?
  8. wait $PID2
  9. RET2=$?
  10. if [ $RET1 == 0 ] && [ $RET2 == 0 ]; then
  11. echo succeeded
  12. exit 0
  13. else
  14. echo failed
  15. exit 1
  16. fi

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.