Path: csiph.com!weretis.net!feeder6.news.weretis.net!news.linkpendium.com!news.linkpendium.com!panix!usenet.stanford.edu!not-for-mail From: Robert Elz Newsgroups: gnu.bash.bug Subject: Re: Fwd: Don't set $?=130 when discarding the current command line (not run yet) with CTRL-C? Date: Sat, 23 Nov 2019 16:50:00 +0700 Lines: 76 Approved: bug-bash@gnu.org Message-ID: References: <4b15601c-1b0d-01c5-990e-7fdf4600fb9e@case.edu> <20900.1574502600@jinx.noi.kre.to> NNTP-Posting-Host: lists.gnu.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: usenet.stanford.edu 1574502664 23334 209.51.188.17 (23 Nov 2019 09:51:04 GMT) X-Complaints-To: action@cs.stanford.edu Cc: Chet Ramey , "bash.bug list" To: Clark Wang Envelope-to: bug-bash@gnu.org In-Reply-To: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 2001:3c8:9009:181::2 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: <20900.1574502600@jinx.noi.kre.to> X-Mailman-Original-References: <4b15601c-1b0d-01c5-990e-7fdf4600fb9e@case.edu> Xref: csiph.com gnu.bash.bug:15628 Date: Fri, 22 Nov 2019 16:16:58 +0800 From: Clark Wang Message-ID: | Curious why people care about this? For some people it seems to be related to wanting to see $? in their prompt, and either have it explicit that a SIGINT interrupted command entry, or continue with previous $? .. For me it is partly just because of what $? is. From posix: ? Expands to the decimal exit status of the most recent pipeline (see Section 2.9.2). nothing about being altered by anything other than (at least attempted) execution of a pipeline (ie: some command or other). More practically, the times when I want it are when I have run a command, then start typing the next one, and realise that I really meant to check the exit status of the last one before running another. If I finish typing my next command I just mentally curse my forgetfulness, and take whatever action I can (often re-running the previous command, if that makes sense). But if I catch it before I have finished the next command, I have the opportunity to abort what I'm doing, and check $? before it is lost. If that happens while still on the first (or only) line of the new command, then a line kill char (^U often) is OK, deletes whatever I typed, and I can replace that with "echo $?" or whatever. But if it happens after a \n has been entered, that no longer works, whereas SIGINT (^C usually) does: Compare bash... jinx$ false jinx$ while sleep 3 do ^C jinx$ echo $? 130 (in bash my PS2 is set to be (become really) invisible so I can cut/paste whole command sequences) to the NetBSD sh (where editline doesn't handle my PS2 "properly") [jinx]{2}$ false [jinx]{2}$ while sleep 3 > do > [jinx]{2}$ echo $? 1 [jinx]{2}$ true [jinx]{2}$ while sleep 3 > do > [jinx]{2}$ echo $? 0 (there was a ^C, not echoed explicitly, after the PS2 prompt on the line after each "do" ... the lack of the echo another difference between editline and readline I assume, the ^C is echoed if I disable editline and just use the tty driver, my PS2 also works as planned then). [jinx]{2}$ set +V [jinx]{2}$ true [jinx]{2}$ while sleep 3 do ^C [jinx]{2}$ echo $? 0 kre