[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Shouldn't this script terminate on ^C?

From: Chet Ramey
Subject: Re: Shouldn't this script terminate on ^C?
Date: Tue, 19 Feb 2013 15:17:55 -0500
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:17.0) Gecko/20130107 Thunderbird/17.0.2

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


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


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.

``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU    chet@case.edu    http://cnswww.cns.cwru.edu/~chet/

reply via email to

[Prev in Thread] Current Thread [Next in Thread]