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


Groups > gnu.bash.bug > #15628

Re: Fwd: Don't set $?=130 when discarding the current command line (not run yet) with CTRL-C?

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 <kre@munnari.OZ.AU>
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 <mailman.2384.1574502663.13325.bug-bash@gnu.org> (permalink)
References <CADv8-ogRv-atdWkiRNWdVA=V03XKpq4AF1-pDTmc=PmKUiHK_w@mail.gmail.com> <CADv8-ogKo=wDshxPiJj8D+BydvcOFS99KQ5pDjWCu7a1v=8nwQ@mail.gmail.com> <CADv8-oi+7MQ042_cAjtPrr4Jm=EFjjFLHGxSOPpWwF3066uotA@mail.gmail.com> <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 <chet.ramey@case.edu>, "bash.bug list" <bug-bash@gnu.org>
To Clark Wang <dearvoid@gmail.com>
Envelope-to bug-bash@gnu.org
In-Reply-To <CADv8-ogRv-atdWkiRNWdVA=V03XKpq4AF1-pDTmc=PmKUiHK_w@mail.gmail.com>
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 <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 <20900.1574502600@jinx.noi.kre.to>
X-Mailman-Original-References <CADv8-ogRv-atdWkiRNWdVA=V03XKpq4AF1-pDTmc=PmKUiHK_w@mail.gmail.com> <CADv8-ogKo=wDshxPiJj8D+BydvcOFS99KQ5pDjWCu7a1v=8nwQ@mail.gmail.com> <CADv8-oi+7MQ042_cAjtPrr4Jm=EFjjFLHGxSOPpWwF3066uotA@mail.gmail.com> <4b15601c-1b0d-01c5-990e-7fdf4600fb9e@case.edu>
Xref csiph.com gnu.bash.bug:15628

Show key headers only | View raw


    Date:        Fri, 22 Nov 2019 16:16:58 +0800
    From:        Clark Wang <dearvoid@gmail.com>
    Message-ID:  <CADv8-ogRv-atdWkiRNWdVA=V03XKpq4AF1-pDTmc=PmKUiHK_w@mail.gmail.com>

  | 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

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


Thread

Re: Fwd: Don't set $?=130 when discarding the current command line (not run yet) with CTRL-C? Robert Elz <kre@munnari.OZ.AU> - 2019-11-23 16:50 +0700

csiph-web