Tried to add a function to my control_c interrupt here. It works but has one little bug. If the user selects to run the function instead of exiting, the program restarts itself without forking as it should. However, after that control_c no longer works again. I wanted to allow the user to run this function at anytime by pressing a button, so just running one time won't cut it. I searched Google and the Bash man page on 'exec' but couldn't find anything on this problem. Any advice much appreciated.
control_c()
{
echo -e "Would you like to run this function?\n"
echo -e "Enter y or n: "
read ans
if [ "$ans" == "y" ]; then
# Do function here
sleep 2
exec bash test.sh
exit 0
else
exit 0
fi
}
trap control_c SIGINT