Path: csiph.com!goblin1!goblin.stu.neva.ru!usenet.stanford.edu!not-for-mail From: Martijn Dekker Newsgroups: gnu.bash.bug Subject: trap: interactive bash exits on resending SIGINT twice Date: Tue, 14 Jan 2020 17:24:10 +0100 Lines: 24 Approved: bug-bash@gnu.org Message-ID: References: <9e22237a-78bf-c0bf-efcf-7f536cbed5ea@inlv.org> NNTP-Posting-Host: lists.gnu.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: usenet.stanford.edu 1579019061 1607 209.51.188.17 (14 Jan 2020 16:24:21 GMT) X-Complaints-To: action@cs.stanford.edu To: Bug reports for the GNU Bourne Again SHell Envelope-to: bug-bash@gnu.org User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:68.0) Gecko/20100101 Thunderbird/68.4.1 Content-Language: en-GB X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 37.59.109.123 X-BeenThere: bug-bash@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Bug reports for the GNU Bourne Again SHell List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: <9e22237a-78bf-c0bf-efcf-7f536cbed5ea@inlv.org> Xref: csiph.com gnu.bash.bug:15802 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