Is it possible to get out of a bashscript while loop with CTRL+C and continue in the script instead of exiting it? In my script I have a while function and an menu function. I want to re-run the menu function if CTRL+C is pressed from the running while loop.
#!/bin/bash
function while_loop {
D=1
while [ "1" == $D ]
do
sleep 5
echo $D
done
}
function main_menu {
M="i"
while [ "$M" != "e" ]; do
echo -e "auto update:\ta"
echo -e "exit:\t\te"
read -n 1 M
case $M in
a) while_loop
;;
e)
exit 1
;;
*)
echo "Wrong input!"
esac
done
}
main_menu