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? > > I have tested bash versions 4.2.37(1)-release, 4.1.5(1)-release, > and 3.2.39(1)-release. (Debian Sid, Squeeze and Lenny.) > > All these bash versions output "After loop". > zsh and dash do exit immediately. Which behaviour is correct? > I couldn't find what POSIX says about this.
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 In summary, a non-interactive bash would only respond to a ^C that it received while waiting for a foreground process to exit if that foreground process itself exited with a SIGINT. The long version of that explanation is in Martin Cracauer's excellent http://www.cons.org/cracauer/sigint.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. Read the whole message thread for lots of background. Chet -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, ITS, CWRU c...@case.edu http://cnswww.cns.cwru.edu/~chet/