Skip to content

Instantly share code, notes, and snippets.

@compor
Created February 26, 2013 11:18
Show Gist options
  • Select an option

  • Save compor/ed288d751fa4bd36bbc9 to your computer and use it in GitHub Desktop.

Select an option

Save compor/ed288d751fa4bd36bbc9 to your computer and use it in GitHub Desktop.
trap control in bash
#!/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