trap ctrl+c download function trap_ctrlc() { echo "ctrl+c caught" # ctrl+c callback stuffs here exit 2 } # SIGINT=2 ( man 7 signal ) trap "trap_ctrlc" 2 while true; do echo "$(date) : loop action" sleep 1 done references signal(7)