I am trying to have a confirmation message every time I type exit command in the command-prompt. To do this, I have tried to use trap in .bashrc file but it seem like trap is not a solution as it run the original command anyway. Is there a way I can have this?
Here is my bashrc script code which could not get the job done:
function _exit() # Function to run upon exit of shell.
{
read -p "${RED}Are you sure? " REPLY
if [[ $REPLY =~ ^[Yy]$ ]]; then
echo -e "${RED}Bye${NC}"
exit 0
else
#I do not know what to do here to not exit
return
fi
}
trap _exit EXIT