Skip to content

Instantly share code, notes, and snippets.

@zipizap
Created October 11, 2013 14:17
Show Gist options
  • Save zipizap/6935374 to your computer and use it in GitHub Desktop.
Save zipizap/6935374 to your computer and use it in GitHub Desktop.
#!/bin/bash
# capture SIGINT (emitted when CTRL-C)
function handler__CtrlC {
echo "------- handler_CtrlC -------"
echo ">> Control-C was pressed. Exiting"
exit 1
}
trap handler__CtrlC SIGINT
echo "Handler for CTRL-C is defined - press CTRL-C or wait 5 seconds to continue"
sleep 5
TMP_FILE=$(mktemp)
# capture EXIT signal (emitted just before program finishes)
function handler__Exit {
echo "------- handler_Exit -------"
echo ">> Removing $TMP_FILE and exiting"
rm -f $TMP_FILE
exit 2
}
trap handler__Exit EXIT
echo "Handler for EXIT is defined - going to 'exit 0' now"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment