Setting the following trap makes an interactive bash (any version) exit
on issuing SIGINT:
trap 'trap "true" INT; kill -s INT $$; trap - INT; kill -s INT $$' INT
# ^^^^^^^^^^^^^^^ eat signal ^^^^^^^^^^ unset trap
After setting that trap, pressing Ctrl+C, or otherwise causing SIGINT to
be sent, causes an interactive bash to exit.
Expected behaviour: no exit.
Confirmed on macOS and Debian.
Ignoring the signal instead of merely eating it seems to be an effective
workaround on more recent bash versions:
trap 'trap "" INT; kill -s INT $$; trap - INT; kill -s INT $$' INT
This avoids an interactive shell exiting on SIGINT on bash 4.4 and 5.0,
but not 4.3 or earlier.
- M.
--
modernish -- harness the shell
https://github.com/modernish/modernish