bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: history bug: new shell separates lines from the history file


From: Chet Ramey
Subject: Re: history bug: new shell separates lines from the history file
Date: Mon, 25 Nov 2024 11:22:24 -0500
User-agent: Mozilla Thunderbird

On 11/21/24 9:59 AM, Michael Tosch wrote:

Bash Version: 5.1
Patch Level: 16
Release Status: release

Description:

In bash I do

bash-5.1$
bash-5.1$ shopt| grep hist
cmdhist         on
histappend     off
histreedit     off
histverify     off
lithist         on
bash-5.1$ echo $HISTTIMEFORMAT
%F %T
bash-5.1$ for i in a b c
do
   echo $i
done
a
b
c
bash-5.1$ history 5
   503  2024-11-21 13:44:22 ls
   504  2024-11-21 13:44:31 shopt| grep hist
   505  2024-11-21 13:45:11 echo $HISTTIMEFORMAT
   506  2024-11-21 13:45:26 for i in a b c
do
   echo $i
done
   507  2024-11-21 13:45:51 history 5
bash-5.1$ exit


In a new shell I get

bash-5.1$ history 10
   491  2024-11-21 13:44:22 ls
   492  2024-11-21 13:44:31 shopt| grep hist
   493  2024-11-21 13:45:11 echo $HISTTIMEFORMAT
   494  2024-11-21 13:45:26 for i in a b c
   495  2024-11-21 13:48:30 do
   496  2024-11-21 13:48:30   echo $i
   497  2024-11-21 13:48:30 done
   498  2024-11-21 13:45:51 history 5
   499  2024-11-21 13:48:27 exit
   500  2024-11-21 13:48:46 history 10
bash-5.1$

This is what happens when the calling application (bash, in this case)
doesn't set the flag that tells the history library to treat lines as
potential timestamps before it reads the history file.

Bash does this by setting it when you set HISTTIMEFORMAT to a value. If you
don't set HISTTIMEFORMAT, the history library uses the historical behavior
of line-oriented history, where each line gets a timestamp that bash can
manage. If you do, the history library assumes timestamps are command
delimiters.

The idea is that history files are usually unique per application. If a
previous session writes timestamps to the history file, and the same
application reads it (with the same settings managed in an application-
specific way) in a subsequent session, you'll get the same set of entries.
Bash uses HISTTIMEFORMAT to control writing timestamps, and the same
thing to determine whether or not history entries should be timestamp-
delimited.

This came in in bash-4.4. Here's a message from 2015 describing it:

https://lists.gnu.org/archive/html/bug-bash/2015-12/msg00206.html

--
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    chet@case.edu    http://tiswww.cwru.edu/~chet/

Attachment: OpenPGP_signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]