====== How to trap interrupts in the bash shell ====== #!/bin/bash myCleanup() { rm -f /myapp/tmp/mylog return $? } myExit() { echo -en "\n*** Exiting ***\n" myCleanup exit $? } trap myExit SIGINT # main loop while true do echo -n "Enter your name: " read x echo "Hello $x" done Ref: http://mariusvw.com/2010/05/18/how-to-trap-catch-keyboard-interrupt-in-bash-on-linux-freebsd/ {{tag>linux bash}} ~~LINKBACK~~ ~~DISCUSSION~~