Path: csiph.com!goblin1!goblin.stu.neva.ru!usenet.stanford.edu!not-for-mail From: Greg Wooledge Newsgroups: gnu.bash.bug Subject: Re: Protect Loop Execution with Traps Date: Wed, 29 Jan 2020 15:22:44 -0500 Lines: 18 Approved: bug-bash@gnu.org Message-ID: References: <20200128212551.GD12574@localhost4.local> <20200128020322.GA31704@localhost4.local> <20200128134935.GM1350@eeg.ccf.org> <20200128204932.GB12574@localhost4.local> <20200128210721.GU1350@eeg.ccf.org> <59.1580277932@jinx.noi.kre.to> <20200129143352.GY1350@eeg.ccf.org> <20200129201907.GA17112@localhost4.local> <20200129202244.GL1350@eeg.ccf.org> NNTP-Posting-Host: lists.gnu.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: usenet.stanford.edu 1580329369 21512 209.51.188.17 (29 Jan 2020 20:22:49 GMT) X-Complaints-To: action@cs.stanford.edu Cc: bug-bash@gnu.org To: Roger Envelope-to: bug-bash@gnu.org Mail-Followup-To: Roger , bug-bash@gnu.org Content-Disposition: inline In-Reply-To: <20200129201907.GA17112@localhost4.local> User-Agent: Mutt/1.10.1 (2018-07-13) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 139.137.100.1 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: <20200129202244.GL1350@eeg.ccf.org> X-Mailman-Original-References: <20200128212551.GD12574@localhost4.local> <20200128020322.GA31704@localhost4.local> <20200128134935.GM1350@eeg.ccf.org> <20200128204932.GB12574@localhost4.local> <20200128210721.GU1350@eeg.ccf.org> <59.1580277932@jinx.noi.kre.to> <20200129143352.GY1350@eeg.ccf.org> <20200129201907.GA17112@localhost4.local> Xref: csiph.com gnu.bash.bug:15849 On Wed, Jan 29, 2020 at 03:19:07PM -0500, Roger wrote: > >sigint_handler() { > > trap - INT > > kill -INT $$ > >} > >trap sigint_handler INT > > One thing to note here, I tried inserting the "trap sigint_handler INT" prior > to the loop/for/while statement (or outside of the loop) and the trap doesn't > work as you state it does for yourself. > > I find I have to insert "trap sigint_handler INT" within my loop (for/while) > section of code, for the trap to work. In my eyes or for me, this works as > expected. That sounds like your loop is inside a subshell. Possibly because you're using it in a pipeline, or possibly other reasons.