When Bash is interactive, in the absence of any traps, it ignores
SIGTERM (so that ‘kill 0’ does not kill an interactive shell),
is caught and handled (so that the
wait builtin is interruptible).
When Bash receives a
SIGINT, it breaks out of any executing loops.
In all cases, Bash ignores
If job control is in effect (see Job Control), Bash
Non-builtin commands started by Bash have signal handlers set to the
values inherited by the shell from its parent.
When job control is not in effect, asynchronous commands
SIGQUIT in addition to these inherited
Commands run as a result of
command substitution ignore the keyboard-generated job control signals
The shell exits by default upon receipt of a
Before exiting, an interactive shell resends the
all jobs, running or stopped.
Stopped jobs are sent
SIGCONT to ensure that they receive
To prevent the shell from sending the
SIGHUP signal to a
particular job, it should be removed
from the jobs table with the
builtin (see Job Control Builtins) or marked
to not receive
huponexit shell option has been set with
(see The Shopt Builtin), Bash sends a
SIGHUP to all jobs when
an interactive login shell exits.
If Bash is waiting for a command to complete and receives a signal
for which a trap has been set, the trap will not be executed until
the command completes.
When Bash is waiting for an asynchronous
command via the
wait builtin, the reception of a signal for
which a trap has been set will cause the
wait builtin to return
immediately with an exit status greater than 128, immediately after
which the trap is executed.
When job control is not enabled, and Bash is waiting for a foreground
command to complete, the shell receives keyboard-generated signals
SIGINT (usually generated by ‘^C’) that users
commonly intend to send to that command.
This happens because the shell and the command are in the same process
group as the terminal, and ‘^C’ sends
SIGINT to all processes
in that process group.
See Job Control, for a more in-depth discussion of process groups.
When Bash is running without job control enabled and receives
while waiting for a foreground command, it waits until that foreground
command terminates and then decides what to do about the
SIGINT, Bash concludes that the user meant to end the entire script, and acts on the
SIGINT(e.g., by running a
SIGINTtrap or exiting itself);
SIGINT, the program handled the
SIGINTitself and did not treat it as a fatal signal. In that case, Bash does not treat
SIGINTas a fatal signal, either, instead assuming that the
SIGINTwas used as part of the program’s normal operation (e.g.,
emacsuses it to abort editing commands) or deliberately discarded. However, Bash will run any trap set on
SIGINT, as it does with any other trapped signal it receives while it is waiting for the foreground command to complete, for compatibility.