On 4/17/20 3:59 PM, gentoo_eshoes--- via Bug reports for the GNU Bourne
Again SHell wrote:
> I've noticed that if I trap SIGINT in a bash script, the behavior when 
> encountering C-c depends on whether an external command (eg. 'sleep 100') or 
> a builtin command (like 'read -p') was encountered.

It's only `read', and it happens when bash is executing in default mode.
Here's what I wrote (off-list) earlier this month about it; it has come
up several times before:

=====
The idea is that trapping the signal doesn't interrupt the read, kind of
like a read system call getting restarted if interrupted by a signal and
reading from the terminal. Since the read doesn't get interrupted, you have
to satisfy it by entering newline. If you didn't have the trap on INT it
would interrupt the read.

Bash has behaved this way in its default mode for just about forever. In
posix mode, it interrupts the read system call.
=====

The behavior of running the trap action and restarting the read if it
returns is still there in default mode for backwards compatibility.

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

  • looking fo... gentoo_eshoes--- via Bug reports for the GNU Bourne Again SHell
    • Re: l... Eduardo Bustamante
      • R... Greg Wooledge
        • ... Eduardo Bustamante
      • R... gentoo_eshoes--- via Bug reports for the GNU Bourne Again SHell
        • ... gentoo_eshoes--- via Bug reports for the GNU Bourne Again SHell
        • ... gentoo_eshoes--- via Bug reports for the GNU Bourne Again SHell
    • Re: l... Chet Ramey
      • R... gentoo_eshoes--- via Bug reports for the GNU Bourne Again SHell
        • ... gentoo_eshoes--- via Bug reports for the GNU Bourne Again SHell
          • ... Chet Ramey
            • ... gentoo_eshoes--- via Bug reports for the GNU Bourne Again SHell
        • ... Chet Ramey

Reply via email to