How to prevent a user from using ctrl-c to stop a script?

I load the script in .bash_profileand this script will ask for the correct password whenever the user opens a terminal window. If the user enters the wrong code, the script will run exitto stop the current terminal.

if [ $code = "980425" ]; then
    echo hello
else
    exit
fi

But I understand that the user can always use ctrl- c to stop the script and enter the terminal. How to avoid this?

+4
source share
1 answer

You can always catch SIGINT:

trap 'echo got SIGINT' SIGINT

Once you're done, set the default handler again with

trap SIGINT

. POSIX . Bourne, bash.

+6

All Articles