Trap Ctrl-C in script

#!/bin/bash
 
#trapping Control + C
#these statements must be the first statements in the script to trap the CTRL C event
 
trap ctrl_c INT
 
function ctrl_c()  {
        logMsgToConfigSysLog "INFO" "INFO: Aborting the script."
        exit 1
}
 
#Rest of script
 
linux/trap-ctl-c.txt · Last modified: 28/09/2021 10:29 by andrew