Skip to content

Instantly share code, notes, and snippets.

@iinm
Last active October 11, 2020 08:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iinm/24a8b8011fc23079310baae130d61d36 to your computer and use it in GitHub Desktop.
Save iinm/24a8b8011fc23079310baae130d61d36 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
set -eu
on_exit() {
exit_status="$?"
echo "--- on_exit: exit_status=$exit_status"
return "$exit_status"
}
on_cancel() {
echo "--- on_cancel:"
trap -- EXIT
trap -- TERM
kill -s TERM $$
}
trap 'on_exit' EXIT
trap 'on_cancel' HUP INT QUIT TERM
"$@" &
wait "$(jobs -p)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment