Skip to content

Instantly share code, notes, and snippets.

@akskap
Last active May 4, 2020 13:51
Show Gist options
  • Save akskap/b3da0004844705db517f2b6f9890817a to your computer and use it in GitHub Desktop.
Save akskap/b3da0004844705db517f2b6f9890817a to your computer and use it in GitHub Desktop.
Trap handling in bash
function handle_exit() {
// Add cleanup code here
// for eg. rm -f "/tmp/${lock_file}.lock"
// exit with an appropriate status code
}
// trap <HANDLER_FXN> <LIST OF SIGNALS TO TRAP>
trap handle_exit 0 SIGHUP SIGINT SIGQUIT SIGABRT SIGTERM
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment