[bug #68645] Confusing rules on appending to HISTFILE

Ilya <[email protected]>
Newsgroups gmane.comp.shells.bash.bugs
Message-ID <[email protected]>
URL:
  <https://savannah.gnu.org/bugs/?68645>

                 Summary: Confusing rules on appending to HISTFILE
                   Group: The GNU Bourne-Again SHell
               Submitter: ilya_the_human
               Submitted: Tue 25 Aug 2026 04:19:48 PM UTC
                Category: None
                Severity: 3 - Normal
                Priority: 5 - Normal
              Item Group: None
                  Status: None
                 Privacy: Public
             Assigned to: None
             Open/Closed: Open
         Discussion Lock: Unlocked


    _______________________________________________________

Follow-up Comments:


-------------------------------------------------------
Date: Tue 25 Aug 2026 04:19:48 PM UTC By: Ilya <ilya_the_human>
Reference says
```
When a shell with history enabled exits, Bash copies the last $HISTSIZE
entries from the history list to the file named by $HISTFILE. If the
histappend shell option is set (see Bash Builtin Commands), Bash appends the
entries to the history file, otherwise it overwrites the history file.
```

But if we look at the code (bashhist.c:512-523), we see that the history does
not work like that at all, and append happens basically always 
```
	  using_history ();
	  if (history_lines_this_session <= where_history () ||
force_append_history)
	    {
	      result = append_history (history_lines_this_session, hf);
	      history_lines_in_file += history_lines_this_session;
	    }
	  else
	    {
	      result = write_history (hf);
	      history_lines_in_file = history_lines_written_to_file;
	      /* history_lines_in_file = where_history () + history_base - 1; */
	    }
```
the only case when the history is actually overwritten is as follows - in one
session I write more commands (history_lines_this_session) than HISTSIZE
(where_history(), which returns history_length), which is a pretty improbable
scenario. I don't at all understand why it is this way

I suppose the historic behavior better be preserved, so I will not offer a
potential fix (which I feel would be to remove `history_lines_this_session <=
where_history ()` condition?), but the docs at least should be patched.
Current text is extremely confusing, in reality "histappend" opt feels mostly
redundant 

P.S. the phrase "copies the last $HISTSIZE entries from the history list"
itself also sounds weird, since the history list is already no more than
$HISTSIZE elements long







    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?68645>

_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/
signature.asc (application/pgp-signature, 228 B)
-----BEGIN PGP SIGNATURE-----

iHUEABYIAB0WIQQk97aszIMMAvLLwm6qLAuaBUf3TgUCao3AqQAKCRCqLAuaBUf3
Th6aAQC8CndqsTvTjTjBCeX/NvprVSd46gCKjTYqvfbuxhRdxwEA9W20pmU47taj
pMhEvbQC8xJucGC2mvqz4GzPzJQpaQQ=
=yQym
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.