Hi,
I have a script where I want to trap 'ctrl-c' so I can do some things before exiting.
Entering 'Q' works OK.
But when I do ^c (ctrl-c), and answering 'y', thus exiting, I get the described effects.
Something to do with 'read -s'?
Code:
#!/bin/bash
# on 'Ctrl-C', call function 'QUIT'
#trap QUIT TERM INT
trap QUIT 2
function QUIT
{
#echo -e " \n"
#echo -e "\033[0m"
echo -n "Are you sure you want to quit? (y/n): "
read ANSWER
if [ "$ANSWER" = "y" ] ; then echo ; exit 0 ; fi
PRINT
}
function PRINT
{
echo "-Menu-"
echo " 1) blabla"
echo " 2) blablabla"
}
# main loop
while :
do
PRINT
#read -n1 KEY # this works
read -s -n1 KEY # this does not
case $KEY in
"1" ) echo "not implemented yet" ; sleep 1 ;;
"2" ) echo "not implemented yet" ; sleep 1 ;;
"Q" ) QUIT ;;
* ) echo "unknown key:'$KEY'" ; sleep 1 ;;
esac
done
echo "-END-"
exit 0