I've been reading various posts about handling SIGINT
in bash
, but I still don't properly understand it.
I know that trap '_handler_name' SIGINT
runs _handler_name
when the signal is received. (People always seem to put it in single quotes, but I don't know why. It doesn't seem necessary to me.)
I was hoping to be able to trap SIGINT
and handle it without aborting a loop in my script, but that only seems to work when the loop is in its own subshell. (I don't know why that is...)
I had thought that using trap -- '_handler_name' SIGINT
might somehow stop other parts of the script from aborting when the signal is received. (This is based upon my reading of this answer.)
So my main question is: what effect does the --
have on trap
. I thought that always just meant "that's the end of the switches" but the example I was looking at didn't have a -
after that, so it looks redundant.
And sub-questions that would help my understanding are: what effect does trap
have on subshells? and why do people put the handler name in quotes in the trap
command?
For context, what I'm trying to do is spot a SIGINT, politely kill a couple of processes, then wait for a few seconds for everything to finish before exiting manually.
PS This article was interesting, though I didn't manage to get my solution from reading it.
UPDATE: I've moved what was here to a new question, since it turns out that what I'm asking here isn't the cause of the issue I've observed.