URL:
  <https://savannah.gnu.org/bugs/?68646>

                 Summary: history -w does not reset history_lines_this_session
                   Group: The GNU Bourne-Again SHell
               Submitter: ilya_the_human
               Submitted: Tue 25 Aug 2026 07:16:56 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 07:16:56 PM UTC By: Ilya <ilya_the_human>
I think this one, unlike my previous bug reports, cannot unfortunately be
explained as a documentation issue

history_lines_this_session is described as
```
/* The number of lines that Bash has added to this history session.  The
   difference between the number of the top element in the history list
   (offset from history_base) and the number of lines in the history file.
   Appending this session's history to the history file resets this to 0. */
int history_lines_this_session;
```

Appending resets the counter, okay. We can test it: (.bashrc only contains
HISTCONTROL=ignorespace" for the purposes of the demo)

```
[ilya@arch ~]$  cat .bash_history
1
2
3
[ilya@arch ~]$ a
bash: a: command not found
[ilya@arch ~]$ b
bash: b: command not found
[ilya@arch ~]$  history -a
[ilya@arch ~]$  cat .bash_history
1
2
3
a
b
[ilya@arch ~]$  history -a
[ilya@arch ~]$  cat .bash_history
1
2
3
a
b
```
a,b commands are appended once. BUT look at what happens if we instead use
`history -w` instead of the first `history -a`
```
[ilya@arch ~]$  cat .bash_history
1
2
3
[ilya@arch ~]$ a
bash: a: command not found
[ilya@arch ~]$ b
bash: b: command not found
[ilya@arch ~]$  history -w
[ilya@arch ~]$  cat .bash_history
1
2
3
a
b
[ilya@arch ~]$  history -a
[ilya@arch ~]$  cat .bash_history
1
2
3
a
b
a
b
```
a,b are appended twice, although history file is technically already "synced"
to local history with `history -w`
This issue is especially bad when exiting, since exit basically always appends
history. So if we've used `history -w` at least once during the session, we'll
get junk in the history file:
```
[ilya@arch ~]$ a
bash: a: command not found
[ilya@arch ~]$ b
bash: b: command not found
[ilya@arch ~]$ history -w
[ilya@arch ~]$ exit
```
hist file contents:
```
1
2
3
a
b
history -w
a
b
history -w
exit
```
Potential fix:
https://codeberg.org/ilya-the-human/bash-fixes/commit/73dc229c6364b4e8ec9075552ba589e6921fc0fe


P.S. There's a similar issue for `history -r`: history_lines_this_session
instead is not increased
```
[ilya@arch ~]$  history
    1  1
    2  2
    3  3
[ilya@arch ~]$ a
bash: a: command not found
[ilya@arch ~]$ b
bash: b: command not found
[ilya@arch ~]$  history -r
[ilya@arch ~]$  history
    1  1
    2  2
    3  3
    4  a
    5  b
    6  1
    7  2
    8  3
[ilya@arch ~]$  history -a
[ilya@arch ~]$  cat .bash_history 
1
2
3
2
3
```
Although it is a separate issue that mostly stems from the fact that on exit
file is never overwritten, so I'll not write about it further







    _______________________________________________________

Reply to this item at:

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

_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/

Attachment: signature.asc
Description: PGP signature

Reply via email to