On Tue, Feb 19, 2013 at 03:17:55PM -0500, Chet Ramey wrote: > On 2/19/13 1:42 PM, Nikolaus Schulz wrote: > > Please consider this bash script: > > > > : | while true; do sleep 1; done > > echo "After loop" > > > > If I hit ^C while it runs, shouln't it terminate?
[...] > You're not going to find anything in Posix. This was discussed > exhaustively two years ago, in a thread starting with > > http://lists.gnu.org/archive/html/bug-bash/2011-02/msg00050.html [...] > It turns out there were some races in bash's implementation of the > intended behavior. Those have been fixed, and the current bash-4.3 > development versions exit the script before the echo. Thanks for the link. So, the behaviour above is a bug triggered by the : exiting before the signal arrives, and bash assuming that : handled the signal. Note that current bash only seems to check the first command in a pipeline for its signal handling, see the following snippet: loop() { while true; do sleep 1; done; } dies() { loop; } exits() { trap 'exit 0' INT; loop; } # This sequence writes "Alive" twice. : | dies ; echo Alive exits | dies ; echo Alive # bash exits here. dies | exits; echo Alive echo "Script completed." The development version of bash works as expected. Nikolaus