Created
February 26, 2013 11:18
-
-
Save compor/ed288d751fa4bd36bbc9 to your computer and use it in GitHub Desktop.
trap control in bash
This file contains hidden or 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 | |
| # http://hacktux.com/bash/control/c | |
| cleanup() | |
| # example cleanup function | |
| { | |
| rm -f /tmp/tempfile | |
| return $? | |
| } | |
| control_c() | |
| # run if user hits control-c | |
| { | |
| echo -en "exiting\n" | |
| cleanup | |
| exit $? | |
| } | |
| # trap keyboard interrupt (control-c) | |
| trap control_c SIGINT | |
| # main() loop | |
| while true; do read x; done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment