Path: csiph.com!xmission!news.snarked.org!news.linkpendium.com!news.linkpendium.com!panix!usenet.stanford.edu!not-for-mail From: Eduardo Bustamante Newsgroups: gnu.bash.bug Subject: Re: looking for consistent C-c trap behavior Date: Fri, 17 Apr 2020 13:02:20 -0700 Lines: 17 Approved: bug-bash@gnu.org Message-ID: References: NNTP-Posting-Host: lists.gnu.org Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" X-Trace: usenet.stanford.edu 1587153764 15119 209.51.188.17 (17 Apr 2020 20:02:44 GMT) X-Complaints-To: action@cs.stanford.edu Cc: bug-bash To: gentoo_eshoes@tutanota.com 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 :cc; bh=Kil069RXJVUnfVmVir4hs/GaJ6yFDxEM/uw5F3wQi0c=; b=Kz2qwTE+9AqzI7ZcWkFU9Tt+3N5U54XCsOUmYbKyx71jzjmBxXWw24cc1cVQycXZEA o+5fKe8wexpvZIQsuYzOWcpK1B0g9ozuA4JkDhQaUUIO0nTPi3L54STnB8RTiD3C2Acn wPDE3SNGfjUdVsXSamliKh/aZAO3C/mW7FGSZnIjegmdHmrquGMbOwU8fnUkoOfU9Sxg pnLxIEDsAsZzWOX5mZthevF52rNTPj11UF07WUNF6mIzSoW2eXwgNLjyAqvSyBiuLP1K fJuMrDogew4uhaecvluCjmIkJjdlL2EJ7jbkUMSxl4khg+nTo9mTsvmfA5joXH7nkzlb BjHw== 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:cc; bh=Kil069RXJVUnfVmVir4hs/GaJ6yFDxEM/uw5F3wQi0c=; b=fwGRAx8yxD6w1a0GBXgP8coqDAJlOSfT9tKPj7SWT4ogwiceNXVToPJjnq7TShI6w3 9Dt27qGS6Pf37ItaLNgqrcaHqOPF0xgFjikpuxrX+YcyOKwefbmQDfQIS6d0OPJ0Clpi g4gRTdyH9M5kSMAwOA2sd94RXgkfUV97QyCxXCU8lcNpIX6/0eGovSLYfChf3XNJULU9 O6F5uT143+68n2XqCGH29cixVn/0QlAl8g43Kv5geR+2kqa6VATUMVzMLjXwsky0fSlk zYasL1qWpcxzJ/PrP3GI/IePVU8NomYlJF6PInjltNvhugqdaISzMK1ScYu8BIFtHwWT srUQ== X-Gm-Message-State: AGi0Pubn5MyvBjpjMXSYvwOKmQLZhbO8dW6iz+4UDqixQnl2oJ1qyakM r2oEBhO1yQiHcbCBMoLn9opQVMDNpEd/fel/v2Y= X-Google-Smtp-Source: APiQypJKpM05nSPp7DxzwTJZXL1pnxIz2UOWNSjs7VuJzLCRnSvJTaJ5EH3iqE+92Q7N0MLerur6j1OpXnyJmyncWO0= X-Received: by 2002:a05:6102:2007:: with SMTP id p7mr3904167vsr.181.1587153751624; Fri, 17 Apr 2020 13:02:31 -0700 (PDT) In-Reply-To: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::e2c X-BeenThere: bug-bash@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Bug reports for the GNU Bourne Again SHell List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: X-Mailman-Original-References: Xref: csiph.com gnu.bash.bug:16152 On Fri, Apr 17, 2020 at 12: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. > > 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.