Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #16157

Re: looking for consistent C-c trap behavior

From Eduardo Bustamante <dualbus@gmail.com>
Newsgroups gnu.bash.bug
Subject Re: looking for consistent C-c trap behavior
Date 2020-04-17 13:17 -0700
Message-ID <mailman.541.1587154678.3066.bug-bash@gnu.org> (permalink)
References <M58iOBd--3-2@tutanota.com> <CAOSMAuuow0=Q7dzYyw3DnYduX79+Cqcc1jyb6q3KZK+z3ofzpg@mail.gmail.com> <20200417200916.GT845@eeg.ccf.org> <CAOSMAuvoBJC4wzAkW1ZyGfVGGmqottaR3fwT8DhfPZ6VpjG5+A@mail.gmail.com>

Show all headers | View raw


On Fri, Apr 17, 2020 at 1:09 PM Greg Wooledge <wooledg@eeg.ccf.org> wrote:
>
> On Fri, Apr 17, 2020 at 01:02:20PM -0700, Eduardo Bustamante wrote:
> > On Fri, Apr 17, 2020 at 12:59 PM gentoo_eshoes--- via Bug reports for
> > the GNU Bourne Again SHell <bug-bash@gnu.org> 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.
> > >
> > > I attach an example script which requires me to press C-c twice to interrupt the builtin 'read -p' command, and it only works because I'm restoring the trap via 'trap - SIGINT' the first time.
> > >
> > > My goal is to have C-c interrupt and use that exit code (130 most likely) to exit with from script, regardless or whether or not the interrupted command in the script was an internal or external one.
> > >
> > > How to do?
> >
> > I recommend reading: https://www.cons.org/cracauer/sigint.html
> >
> > The problem is that the signal is sent to the foreground process. When
> > "sleep" is running, it's the sleep command that receives the signal
> > and decides what to do with it. Not bash.
>
> That's not quite right.  When you press ^C in a terminal, SIGINT is sent
> to *all* of the processes in the "foreground" process group -- both sleep
> and bash, in the case you're discussing.

Oops. Apologies for giving out incorrect information.

And thank you for taking your time to explain it properly.

Back to gnu.bash.bug | Previous | Next | Find similar


Thread

Re: looking for consistent C-c trap behavior Eduardo Bustamante <dualbus@gmail.com> - 2020-04-17 13:17 -0700

csiph-web