[Top][All Lists]

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

Re: [Help-bash] History always appended even though histappend set to of

From: Chet Ramey
Subject: Re: [Help-bash] History always appended even though histappend set to off
Date: Tue, 10 May 2016 21:33:48 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:45.0) Gecko/20100101 Thunderbird/45.0

On 5/3/16 6:28 PM, john smith wrote:
> When I start bash with --norc histappend is set to off as expected:
> $ shopt | grep histappend
> histappend      off
> After starting bash with --norc in two different terminal windows I
> expect only history of the last closed window to be saved.
> However, I always end up with history from both windows saved in
> ~/.bash_history after exiting as if histappend was set.  I checked
> the source code and the reason for this behavior is in
> maybe_save_shell_history() in this line:
> if (history_lines_this_session <= where_history () || force_append_history)

The first clause is a heuristic.  It's been in bash for at least 25 years
(I quit looking when I got back to the 1991 code.)

history_lines_this_session is what it seems like: the number of history
entries added during this shell session.  where_history() is the length
of the history list, the offset of the most recent history entry.  If
the number of this session's history entries is less than the total number
of history entries, we have history entries that we read from a history
file, presumably at shell startup.  This code attempts to preserve those
by appending the new entries to the history file.

If the size of the history list has been limited (`stifled'), the number
of history entries is clamped at that limit (usually $HISTSIZE).  In that
case, as new entries are added, old entries are removed from the front
of the list, and there are definitely entries from the history file that
no longer appear in the history list.

The idea is to avoid losing history file entries if you can help  it.

If you want the history file to be overwritten, you can put `history -w' in
your .bash_logout or in an exit trap for interactive shells.

``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU    address@hidden

reply via email to

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