Created
September 12, 2019 17:42
-
-
Save dcapwell/b147210c54f2ef28e6dcb0f409c060f4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/env bash | |
#set -o xtrace | |
set -o errexit | |
set -o pipefail | |
set -o nounset | |
bin="$(cd "$(dirname "$0")" > /dev/null; pwd)" | |
longrunning() { | |
sleep 10 | |
echo "done" | |
} | |
failing() { | |
return 42 | |
} | |
_main() { | |
pids=() | |
# launch long running commands which pass | |
for i in $(seq 0 10); do | |
longrunning & | |
pids+=($!) | |
done | |
# launch commands which fail | |
for i in $(seq 0 10); do | |
failing & | |
pids+=($!) | |
done | |
# need to loop over each pid to get wait to return the pids status | |
# if the command fails, then this will cause wait to also fail (same rc) and "set -o errexit" will fail the script | |
for p in "${pids[@]}"; do | |
wait "$p" | |
done | |
} | |
_main "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment