Created
December 20, 2016 22:31
-
-
Save mthomas/ef9e1ebfa6435c7aefd2ee08ae0df2e0 to your computer and use it in GitHub Desktop.
Run several commands in bash, in parallel. Let all complete regardless of return code. Return 1 if any fail.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -o errexit | |
set -o pipefail | |
pids="" | |
RESULT=0 | |
(sleep 1; echo 'a'; exit 1) & | |
pids="$pids $!" | |
(sleep 2; echo 'b'; exit 0) & | |
pids="$pids $!" | |
(sleep 3; echo 'c'; exit 0) & | |
pids="$pids $!" | |
for pid in $pids; do | |
wait $pid || let "RESULT=1" | |
done | |
echo "done" | |
if [ "$RESULT" == "1" ]; | |
then | |
exit 1 | |
fi | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Goals...