Created
October 11, 2013 14:17
-
-
Save zipizap/6935374 to your computer and use it in GitHub Desktop.
This file contains 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
#!/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