I've add a trap to my bash script so when CTRL+C is pressed a message appears Do you want to quit ? (y/n)
This works at most parts of the script, but fails at others.
I've created a simple example that shows it always failing.
#!/bin/bash
quit() {
echo "Do you want to quit ? (y/n)"
read ctrlc
if [ "$ctrlc" = 'y' ]; then
exit
fi
}
trap quit SIGINT
trap quit SIGTERM
while true; do
echo -e "\n\e[91mIs everything done ? (y/n)\e[0m"
read -i "y" -e yn
case $yn in
[Nn]* ) continue;;
[Yy]* )
echo -e "Done"
break;;
* ) echo -e "\e[91mPlease answer yes or no.\e[0m";;
esac
done
Why when I press CTRL+C does this pop up Do you want to quit ? (y/n)
but not allow me to exit ? How do I solve it ?
Thanks