From d4494ebdeb3340f98a7a79244601b5d574ae36d1 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Wed, 5 Apr 2023 09:31:50 +0100 Subject: ash: special treatment for read builtin When INT is being trapped the read builtin gets special treatment in bash. In a top-level interactive shell interrupting the read with Ctrl-C clears the input and allows the user to enter a new string. In a subshell Ctrl-C really does interrupt the read and the trap isn't executed. zsh works similarly, except that in the latter case the trap is executed. dash interrupts the read and executes the trap in both cases. ksh also interrupts the read in both cases but only executes the trap in the first. Implement the bash behaviour. (GitHub issue #303) --- shell/ash.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/shell/ash.c b/shell/ash.c index 0863689e8..77670ebb4 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -15462,7 +15462,10 @@ readcmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) write(STDOUT_FILENO, "^C", 2); pending_int = 1; dotrap(); - goto again; + if (!(rootshell && iflag)) + return (uintptr_t)0; + else + goto again; } else if (iflag) { raise_interrupt(); } else { -- cgit v1.2.3-55-g6feb