Hi,

I have run into a rather weird behaviour related to SIGINT, which
doesn't seem to be intended, as it's not consistent with other shells
(and is so unexpected that it took me a while to figure out what was
going wrong in my script!).

When Bash receives SIGINT while executing a command, it normally waits
for the command to complete, and then aborts execution. However, it
looks like somehow, this is not the case if the command handles SIGINT,
and execution continues after the command completes. For instance:

$ bash -c '(trap "echo INT; exit 1" INT; sleep 60s); echo after'
^CINT
after
$

Whereas:

$ bash -c '(sleep 60s); echo after'
^C
$

The command doesn't need to be a subshell; for instance, since Python
handles SIGINT by default, execution continues as well:

$ bash -c 'python -c "import time; time.sleep(60)"; echo after'
^CTraceback (most recent call last):
  File "<string>", line 1, in <module>
KeyboardInterrupt
after
$

dash, mksh, zsh don't exhibit this behaviour: in all cases, execution is
aborted. Bash seems to have always behaved like that, at least since 4.0.

Kevin

Reply via email to