I don't know what's wrong but this script doesn't work. It should be always goes back to menu everytime I press CTRL+C.
#!/bin/bash
func_info()
{
clear
echo "This is info page."
read -p "Press CTRL+C to back to menu or press enter exit..."
exit
}
func_menu()
{
clear
trap - SIGINT
echo "This is menu page."
read -p "Press enter to go to info page..."
trap func_menu SIGINT
func_info
}
func_menu
It works for the first CTRL+C but the second times it just doesn't works.
I'm new to this so please don't judge me ;)
Any helps appreciated :) Thanks.
EDIT:
Actually, I found this works
#!/bin/bash
func_info()
{
clear
echo "This is info page."
read -p "Press CTRL+C to back to menu or press enter exit..."
exit
}
func_menu()
{
clear
echo "This is menu page."
read -p "Press enter to go to info page..."
( trap exit SIGINT; func_info )
func_menu
}
func_menu
But is that OK?