You can block / control ctrl-c
in bash script by following:
#!/bin/bash
trap ctrl_c INT
function ctrl_c() {
echo "Cleaning up some stuff before quiting..."
# Do your stuff here
# For example: kill any background task that you ran
# Don't forget to exit after your cleanup is done
# otherwise the script will not be stopped
exit
}
# here goes your rest of the script
Top comments (0)