Interrupt (Control-C) Handler (aka trap) for bash scripts


```bash exitfn () { trap SIGINT echo; echo "INFO: interrupted" exit } trap "exitfn" INT ``` Note: the line of the script is interrupted and not restarted, so if you don't `exit` in the handler, execution resumes at the next line of the script. [source](https://www.linuxjournal.com/content/bash-trap-command)

Tags:  bash

Share: