Write a script that counts how many times a user tries to quit the program with an interrupt (typically Control-C), showing the count and finally letting them quit on the fifth attempt. Tip: You'll need to use trap for this and the interrupt signal is SIGINT
What will be an ideal response?
count=0
trap 'interrupt' 2
interrupt()
{
echo "I won't quit. Count = $count"
count=$(( ${count} + 1 ))
if [ $count -eq 5 ] ; then
echo "Enough! I'll quit, I'll quit."
exit 1
fi
}
echo "Use Control-C to try and quit this script."
sleep 9999
Computer Science & Information Technology
You might also like to view...
The prompt() method has just one parameter, the string that will display to prompt the viewer
Indicate whether the statement is true or false
Computer Science & Information Technology
Lossless web image format that's best for icons and logos.
a. JPEG b. PNG c. GIF d. ICO
Computer Science & Information Technology