Trap Ctrl-C in a Bash script

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
}
Answered by anonymous.

Leave a Reply

Your email address will not be published. Required fields are marked *