bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

trap: interactive bash exits on resending SIGINT twice


From: Martijn Dekker
Subject: trap: interactive bash exits on resending SIGINT twice
Date: Tue, 14 Jan 2020 17:24:10 +0100
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:68.0) Gecko/20100101 Thunderbird/68.4.1

Setting the following trap makes an interactive bash (any version) exit on issuing SIGINT:

trap 'trap "true" INT; kill -s INT $$; trap - INT; kill -s INT $$' INT
#     ^^^^^^^^^^^^^^^ eat signal       ^^^^^^^^^^ unset trap

After setting that trap, pressing Ctrl+C, or otherwise causing SIGINT to be sent, causes an interactive bash to exit.

Expected behaviour: no exit.
Confirmed on macOS and Debian.

Ignoring the signal instead of merely eating it seems to be an effective workaround on more recent bash versions:
trap 'trap "" INT; kill -s INT $$; trap - INT; kill -s INT $$' INT
This avoids an interactive shell exiting on SIGINT on bash 4.4 and 5.0, but not 4.3 or earlier.

- M.

--
modernish -- harness the shell
https://github.com/modernish/modernish



reply via email to

[Prev in Thread] Current Thread [Next in Thread]