On 11/8/16 1:50 PM, Martijn Dekker wrote: > Works as expected: The 'trap' command is on the same command line as the > loop. The signal is properly ignored, the trap is properly executed > repeatedly on pressing Ctrl+C. > > $ trap 'echo INT' INT; i=0; while [ $((i+=1)) -lt 1000000 ]; do :; done > ^CINT > ^CINT > ^CINT > $ echo $? $i > 0 1000000 > > Buggy behaviour: The 'trap' command is on a separate command line. > The signal is not ignored. The trap is executed once on Ctrl+C and the > loop is interrupted. > > $ trap 'echo INT' INT > $ i=0; while [ $((i+=1)) -lt 1000000 ]; do :; done > ^CINT
Thanks for the report. This is actually something I had flagged to look at after bash-4.4 was released: /* XXX - why do we set this every time through the loop? And why do it if SIGINT is trapped in an interactive shell? */ It looks like not that many people trap SIGINT in an interactive shell. Chet -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, UTech, CWRU c...@case.edu http://cnswww.cns.cwru.edu/~chet/