[bug #68650] HISTFILE truncation on open disrespects timestamps
Ilya <[email protected]>
| Newsgroups | gmane.comp.shells.bash.bugs |
|---|---|
| Message-ID | <[email protected]> |
URL:
<https://savannah.gnu.org/bugs/?68650>
Summary: HISTFILE truncation on open disrespects timestamps
Group: The GNU Bourne-Again SHell
Submitter: ilya_the_human
Submitted: Wed 26 Aug 2026 03:40:59 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: Wed 26 Aug 2026 03:40:59 PM UTC By: Ilya <ilya_the_human>
History file is supposed to be truncated by HISTFILESIZE _entries_, not lines.
But this does not work on shell open. This bug makes combination of positive
HISTFILESIZE together with HISTTIMEFORMAT completely unusable
Demonstration: let's fill the history with HISTFILESIZE entries with
timestamps
```
[ilya@arch ~]$ cat .bashrc
[[ $- != *i* ]] && return
HISTCONTROL=ignoreboth
HISTSIZE=5
HISTFILESIZE=5
HISTTIMEFORMAT="%c "
[ilya@arch ~]$ history
[ilya@arch ~]$ cat .bash_history
[ilya@arch ~]$ 1
bash: 1: command not found
[ilya@arch ~]$ 2
bash: 2: command not found
[ilya@arch ~]$ 3
bash: 3: command not found
[ilya@arch ~]$ 4
bash: 4: command not found
[ilya@arch ~]$ 5
bash: 5: command not found
[ilya@arch ~]$ history
1 Wed 26 Aug 2026 19:25:59 +04 1
2 Wed 26 Aug 2026 19:26:00 +04 2
3 Wed 26 Aug 2026 19:26:00 +04 3
4 Wed 26 Aug 2026 19:26:00 +04 4
5 Wed 26 Aug 2026 19:26:01 +04 5
[ilya@arch ~]$ exit
```
After exit we can observe the following contents of .bash_history. Everything
is correct and as expected:
```
#1787757959
1
#1787757960
2
#1787757960
3
#1787757960
4
#1787757961
5
```
But as soon as we open another shell instance, history file gets truncated to
5 lines, not entries!
```
[ilya@arch ~]$ cat .bash_history
3
#1787757960
4
#1787757961
5
[ilya@arch ~]$ history
1 Wed 26 Aug 2026 19:27:26 +04 3
2 Wed 26 Aug 2026 19:26:00 +04 4
3 Wed 26 Aug 2026 19:26:01 +04 5
```
From what I see from the code, this is because HISTTIMEFORMAT is read with
`sv_histtimefmt` on variables.c:682. Which happens before .bashrc loading! And
while the neighboring HISTCONTROL and HISTIGNORE are read one more time
elsewhere, HISTTIMEFORMAT is not
Possible fix: looks like this one cannot be fixed as easily, so I'll write a
fix as soon as this is confirmed to be an undesirable bug
P.S. not sure about GNU LLM policy, but just in case - I've not used ai for
finding the issues, fixing them, or for writing bug reports
_______________________________________________________
Reply to this item at:
<https://savannah.gnu.org/bugs/?68650>
_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/
signature.asc
(application/pgp-signature, 228 B)
-----BEGIN PGP SIGNATURE----- iHUEABYIAB0WIQQk97aszIMMAvLLwm6qLAuaBUf3TgUCao8JDgAKCRCqLAuaBUf3 Tot9AP40etVGmL+eQ3SaOzE0Y74Ht/bGhn8e+rC0g8QbAMjt+QD+L7paYuBlWAwy WjzzA7BrZxLttDlYTOgDSzuP5ro+uQY= =Z2tz -----END PGP SIGNATURE-----