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

Path csiph.com!xmission!news.snarked.org!news.linkpendium.com!news.linkpendium.com!panix!usenet.stanford.edu!not-for-mail
From Eduardo Bustamante <dualbus@gmail.com>
Newsgroups gnu.bash.bug
Subject Re: looking for consistent C-c trap behavior
Date Fri, 17 Apr 2020 13:17:39 -0700
Lines 28
Approved bug-bash@gnu.org
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>
NNTP-Posting-Host lists.gnu.org
Mime-Version 1.0
Content-Type text/plain; charset="UTF-8"
X-Trace usenet.stanford.edu 1587154679 15606 209.51.188.17 (17 Apr 2020 20:17:59 GMT)
X-Complaints-To action@cs.stanford.edu
To bug-bash <bug-bash@gnu.org>
Envelope-to bug-bash@gnu.org
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=ZSxw/Yl2dwHkagspB2TB/qnLKCcSq5+hZEfFxW/YLSk=; b=Sn88HBtR+c+JwCROw6dIvrkBv83sIhHmAZXt1C4r8OnFpqInabhsnhLxbLpA58/V4h Ty/xiOdoWzZVnths7eEYWi344V7npcuRpt6tIfLC1rEUaY95sNnCRwcOc6nXCz9mhStn O+yRuxuTlC5bzMuaL0QkWkhx9TGn95/bSatDm3OWCr3FGRqh8z8cjpHXrykDCgjRYtpb kUNz0qMEnfLXiKdhXaX1ng8fbggI/J9M+dtwuxaa0YSr7RtoIpp4cPh+shkeFXrjTq0B 2pV9lmHaHg0HsWlY/l7Mj/3ofzQL5PUuKvw2e9XZ+k+T1HLo9NK1FZhny42twiVtSVzb F/+Q==
X-Google-DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=ZSxw/Yl2dwHkagspB2TB/qnLKCcSq5+hZEfFxW/YLSk=; b=iYqdrucRgTopDpWajoMQKSnXvCKBpVFl4g1qL7GOVjL5AuChFUNJHMdMH4Q3oQlqgK FIHPV9QibBS+68CzNkichyys5VivtcxFB2Dbw/JdFZRUACdSjW1e0nwyVOaIY95Wxh2y rwuV3uYlBn76GlhkmDNBZaA/LPUQYWBwejCIhwZicJvUhlZQ7cT0c6rgSFPqNlyr61Rl WGB1k71JH2RLkVotfOQd6LJ/94YM+7oe8QleVUm58ZJ3FA2kY6M9N7bvJj6zHqS9xzZH 7qy64ZEDEaam5nTqaiNmZYLdk2ehX00VHXJNMOAFA6PWlFpGyMUsREF5zJTP719yV1PX Qr4g==
X-Gm-Message-State AGi0PuaED6DLdJkQS06W1cXlcuvZQup8L4ytqyC+NVRrIWa0R+FNMc9c 7si4+WMkpI+ZfK88HJiKSat1lyCXHShkPRVbI9IiHICE
X-Google-Smtp-Source APiQypIrCbwIllvR/5n224kSB1TWqV2i/VRi0Nr/CPb29NetvDStWQZNbPEPGuh/EFckjmOUI7EimEYsA8GcSFiPQM4=
X-Received by 2002:a67:f112:: with SMTP id n18mr3865623vsk.20.1587154671587; Fri, 17 Apr 2020 13:17:51 -0700 (PDT)
In-Reply-To <20200417200916.GT845@eeg.ccf.org>
X-detected-operating-system by eggs.gnu.org: Genre and OS details not recognized.
X-Received-From 2607:f8b0:4864:20::e32
X-BeenThere bug-bash@gnu.org
X-Mailman-Version 2.1.23
Precedence list
List-Id Bug reports for the GNU Bourne Again SHell <bug-bash.gnu.org>
List-Unsubscribe <https://lists.gnu.org/mailman/options/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=unsubscribe>
List-Archive <https://lists.gnu.org/archive/html/bug-bash>
List-Post <mailto:bug-bash@gnu.org>
List-Help <mailto:bug-bash-request@gnu.org?subject=help>
List-Subscribe <https://lists.gnu.org/mailman/listinfo/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=subscribe>
X-Mailman-Original-Message-ID <CAOSMAuvoBJC4wzAkW1ZyGfVGGmqottaR3fwT8DhfPZ6VpjG5+A@mail.gmail.com>
X-Mailman-Original-References <M58iOBd--3-2@tutanota.com> <CAOSMAuuow0=Q7dzYyw3DnYduX79+Cqcc1jyb6q3KZK+z3ofzpg@mail.gmail.com> <20200417200916.GT845@eeg.ccf.org>
Xref csiph.com gnu.bash.bug:16157

Show key headers only | 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