From:   Luke Schlather
Subject: Re: Bash History Behavior Suggestion
Date:   Tue, 17 Nov 2026 14:39:22 -0800

>Maybe I should back up and describe my actual problem. I think I had
>assumed the problem was something slightly different from what it actually
>is, and this shopt does fix the problem I have. My actual problem (which I
>view as a bug) is that often I will have several ssh sessions open, my
>connection drops, and the commands I just executed are not in the history
>when I reconnect, even though I have histappend on.

I hope I am not misunderstanding you by too much, but it seems to me
that the real underlying thing here is actually two separate, but
related issues:

    1) That when you lose your connection to the shell, for whatever
    and for any of a large number of reasons, your most recent history
    does not get saved.  The thing is, this is *supposed* to work -
    that is, when the shell is killed by a SIGHUP (the usual case when
    a connection - either serial or TCP/IP or whatever - is dropped),
    the shell is supposed to catch it and ensure that the history file
    is written.  How well this works in practice is up for debate, and
    I (and I'm sure everyone else reading this) has had instances
    where the shell has dropped but the history was not written.

    In any case, the real fix for this is to start using screen (or
    its more recent incarnation, tmux) which will keep your shells
    alive even when you lose your connection.  This doesn't help, of
    course, if your shell dies because of a bug in the shell or if the
    system is rebooted.  But it is a good idea nonetheless.

    2) The problem of having multiple shells open (e.g., multiple
    terminal windows on a desktop) at the same time and they all have
    the same value of HISTFILE.  As noted in some of the posted URLs,
    generally only the history of the most recently closed shell is
    saved, overwriting any data saved by earlier exiting shells.  Note
    that I am aware that there is a "histappend" option, but I'm not
    sure it works as it should and I've never used it (because I
    intrinsically don't trust it).  That said, there are lots of other
    solutions to this problem (as noted in some of the posted URLs)
    and I'm sure everyone has their favorite method.

    But here's the thing: I think what's really needed is an
    officially sanctioned solution to this problem.  I.e., something
    from the official keeper of bash.  I.e., actual policy, not just
    mechanism.  We've got lots of mechanism; what we need is an
    officially blessed solution.

=================================================================================
Please do not send me replies to my posts on the list.
I always read the replies via the web archive, so CC'ing to me is unnecessary.

When responding to my posts, please try to refrain from giving bureaucratic
answers.  If you have nothing useful to say, then just click Next and go on.

BTW, ain't interested in kludgey workarounds - got enough of my own!
(YT id: 6H1lcubN0oE)

Reply via email to