Deutsch   English   Français   Italiano  
<va3mcb$10662$2@news.xmission.com>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!weretis.net!feeder9.news.weretis.net!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail
From: gazelle@shell.xmission.com (Kenny McCormack)
Newsgroups: comp.unix.shell
Subject: (bash) Does the EXIT trap fire if/when bash is exited via a signal?
Date: Wed, 21 Aug 2024 03:19:39 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <va3mcb$10662$2@news.xmission.com>
Injection-Date: Wed, 21 Aug 2024 03:19:39 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
	logging-data="1054914"; mail-complaints-to="abuse@xmission.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)
Bytes: 1571
Lines: 19

Note: This thread is entirely about bash.  No other shells or "POSIX" are
relevant here.  But comparisons between various versions of bash may be
relevant, since I think the behavior may have changed over the versions.

That said, suppose I have something like:

trap 'date > /tmp/somefile' EXIT

# Rest of script

Now, if during "Rest of script", say I hit ^C.  Or ^\.  Or, say I send a
signal via "kill" from another terminal.  Does my exit trap get executed?

I've had varying results.  I am pretty sure that at one point, the answer
was "no", but recently, I've noticed that when I exit via ^C, the EXIT trap
does execute.  I'm curious what the "official" answer is.

-- 
The people who tell us to be proud of the white race are the ones who make
us the most embarrassed by it.