From bash manual
When Bash receives a SIGINT, it breaks out of any executing loops.
When receiving SIGINT, does bash also quit other commands, besides loops (for or while)? Thanks.
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this communityQuoting the bash manual:
When
bash
is interactive, in the absence of any traps, it ignoresSIGTERM
(so thatkill 0
does not kill an interactive shell), andSIGINT
is caught and handled (so that thewait
builtin is interruptible).
Yes, bash quits builtins when it receives SIGINT
. You can verify that with wait
or read
(read
from a large file with no newlines will give you time to press CtrlC). wait
in particular needs to deal with SIGINT
correctly, as per POSIX (along with all other signals it can come across).
SIGINT
themselves (the shell is informed if an external command was killed by a signal, but it deals with that by interpreting the information given by wait(2)
or waitpid(2)
, not by installing a signal handler). if
etc. run at a point in time, so there’s not much point in making them interruptible.
– Stephen Kitt
May 28 '18 at 13:22