Skip to content

Instantly share code, notes, and snippets.

@dcapwell
Created September 12, 2019 17:42
Show Gist options
  • Save dcapwell/b147210c54f2ef28e6dcb0f409c060f4 to your computer and use it in GitHub Desktop.
Save dcapwell/b147210c54f2ef28e6dcb0f409c060f4 to your computer and use it in GitHub Desktop.
#!/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