Trap Ctrl-C in a Bash script Posted on Mar 24, 2018 by Q A In QA How to trap Ctrl-C in a Bash script? The piece of code: # trap ctrl-c and call ctrl_c() trap ctrl_c INT function ctrl_c() { echo echo "Ctrl-C by user" # do the jobs exit } Read more: How to rearrange Alt, Ctrl and Win keys on Linux: Win as Alt and Ctrl/Alt as Ctrl How to get the script’s own path in sourced Bash script? How to spawn a background process in a bash script How to get a script’s directory reliably in Bash on Linux? How to disable an option with a bash script? How to Debug a Bash script? How to add a prefix string at the beginning of each line in Bash shell script on Linux? How to judge whether its STDERR is redirected to a file in a Bash script on Linux?