Run this script. Hit CTRL-C 6 times, and see what happens, and how it works.
Code:
#!/bin/sh
count=0
# Declare function to handle CTRL-C signals
signal_func() {
count=$((count + 1))
echo "INT signal received $count times."
if [ $count -ge 5 ] ; then # After 5 INT's
# reset signal handling to default.
trap - INT
fi
}
# Install handler for INT signals (CTRL-C)
trap 'signal_func' INT
# Loop doing nothing for demo.
while true ; do
sleep 1000000
echo "Woken up"
done
# we never get here.
exit 0