help-bash
[Top][All Lists]
Advanced

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

Re: Exiting the "read" builtin with trapped ^C


From: Stan Marsh
Subject: Re: Exiting the "read" builtin with trapped ^C
Date: Fri, 26 Jun 2026 15:23:14 -0600

From:   Chet Ramey
Subject: Re: Exiting the "read" builtin with trapped ^C
Date:   Fri, 26 Jun 2026 15:29:15 -0400

>On 6/22/26 11:41 AM, Koichi Murase wrote:

>   Why doesn't `continue' in the trap string take effect immediately?

>I think this is indeed a non-trivial question. I don't have a
>particular opinion on which behavior should be preferred.  Both the
>current behavior and the requested behavior of the immediate
>`continue' seem to make sense to me.

>Because the trapped SIGINT doesn't cause the `read' builtin to complete,
>and the `continue' will only take effect when it does.

Right.  This all makes perfect sense to me now.
As you say (in the other post), different shells do this differently,
and the bash way is certainly an acceptable way.

Although it seems weird (*), I'm happy and comfortable with my
solution.

(*) Even though as one correspondent notes, TIOCSTI is (quote-unquote)
"deprecated".  It works for me on the systems that I care about.

A couple of other notes:

    1) Yes, none of this would happen if I didn't trap INT, but that,
    of course, is the whole point of the exercise (to trap INT so that
    the script can continue).

    2) Note (just for the record) that the trap *does* execute
    immediately, when ^C is hit (which you can see from the displayed
    message).  It is just that the 'read' doesn't exit (and thus the
    'continue' doesn't execute) until the 'read' sees a line-terminator.

=================================================================================
Please do not send me replies to my posts on the list.
I always read the replies via the web archive, so CC'ing to me is unnecessary.

When responding to my posts, please try to refrain from giving bureaucratic
answers.  If you have nothing useful to say, then just click Next and go on.



reply via email to

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