I am trying to trap the Ctrl+C signal asking a confirmati开发者_如何学编程on from the user. The trapping part works fine. But once the signal gets trapped and the user presses NO
, it does not return to the normal execution. Instead, it quits the script. How to make it resume execution when the user presses no
?
Here is my code:
hell()
{
echo "Do you want to quit? Press 1 for yes and 0 for no";
read n;
if [ $n == 1 ]; then
exit 1;
fi
}
trap "hell" SIGINT
find /
The problem here is the INT signal is being received by your script AND by your command find /
, so it exits.
You can fully ignore the signal(s) with:
trap '' SIGNINT
I don't know if it's possible to catch the signal and prevent that your commands receive it.
精彩评论