4 ms·
> - Trap ctrl+c to gracefully exit (details here https://www.tothenew.com/blog/foolproof-your-bash-script-som https://www.tothenew.com/blog/foolproof-your-bash-
by jancsika 6y ago
> - Trap ctrl+c to gracefully exit (details here https://www.tothenew.com/blog/foolproof-your-bash-script-som https://www.tothenew.com/blog/foolproof-your-bash-script-som...)
I'd rather that most devs don't touch that signal. Using that binding and having a GUI or CLI program continue hanging because the dev screwed up the cleanup is a real pain. And someone writing a Bash script is highly likely for doing something "very clever" with that signal to make my life harder.
Or if you're going to do something with it, at least make it clear you're trolling me. Show me a text add that forces me to choose my favorite Korean boy band before I can exit, or something in that vein.
- exdsq 6y agoThat’s fair! But sometimes I want to have a hook that basically says “Are you sure?” to catch mistakes in the wrong terminal or something. One thing I wrote recently took several hours to run and it’d suck to accidentally close it because I type without looking.
- jmholla 6y agoIn that case, you could not catch CTRL-C in the cleanup.
- nemetroid 6y agoAgree that developers should be very careful about messing up Ctrl-C. However, as others have pointed out, it can make sense for long-running processes (especially in cases where there's an intermediate result that can be output instead of the final result). I think a good compromise is to only ever trap Ctrl-C once, so that a double Ctrl-C always successfully interrupts.