Re: Questions on the behavior of CTLR+C and trap when job control is ena
From:
Chet Ramey
Subject:
Re: Questions on the behavior of CTLR+C and trap when job control is enabled/disabled
Date:
Wed, 4 Jun 2025 14:55:31 -0400
User-agent:
Mozilla Thunderbird
On 6/4/25 1:14 PM, Oğuz wrote:
On Wed, Jun 4, 2025 at 5:09 PM Chet Ramey <chet.ramey@case.edu> wrote:
You are running this with job control enabled, the shell doesn't receive
the SIGINT, the shell notices that `sleep' exited due to SIGINT and
interrupts the `source' (since that is what most people want -- bash
behaves more like a non-interactive shell when it's reading input from
a different source).
`source' is a red herring here, this report boils down to the following
$ trap uname INT
$ sleep 10
^C
$
Other shells (zsh, ksh, ash and pdksh variants) execute the trap
handler on ^C, bash is the outlier.
Yep, it never has. It's documented in bash-5.3:
"When job control is enabled, bash does not receive keyboard-generated
signals such as SIGINT while it is waiting for a foreground command.
An interactive shell does not pay attention to the SIGINT, even if the
foreground command terminates as a result, other than noting its exit
status. If the shell is not interactive, and the foreground command
terminates due to the SIGINT, bash pretends it received the SIGINT it-
self (scenario 1 above), for compatibility."
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU chet@case.edu http://tiswww.cwru.edu/~chet/