🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.unix.shell
Article #4027

Re: bash history: saving to and restoring from different file

#4027
From: S P Arif Sahari Wibowo
Date: Wed, 24 Sep 2008 13:43
47 lines
3253 bytes
On Sun, 21 Sep 2008, jellybean stonerfish wrote:
> Ok, I may have figured out an ugly way to do what you want. 
> I turned my file "~/.bash_history" into a link, and change 
> where it points to.

Wow, thanks for the effort to find the solution! I did a test 
and this apparently works: even when the history file exceed 
HISTFILESIZE, the removal of lines (in the beginning of the 
file) apparently done in-place, without creating new file, 
making sure the link is intact (even hard link will work!).

Now, how bash manage to this file modification in-place is 
another interesting question. Anybody know? :-)

Using the link definitely more elegant than what I think. I also 
thinking about delayed action, but instead using link, by 
changing HISTFILE or running history -r in the actual bash 
environment (by using trap).

The obvious issue is obviously the few seconds delay: it is 
posisble another bash session save the history (either by 
history -a or exiting) while the history file still link to the 
temporary file, rendering that saved history lost.

I found that PROMPT_COMMAND is executed after bash deal with 
history. This potentially can be exploited for this purpose if 
the command actually run in the shell environment not in a 
subshell. Need to be tested.

I also start thinking about another way that will avoid this 
issue altogether: each bash session create new history file. 
Before that, a new session will collect all history files from 
previous sessions, sort uniq and read history from the result. 
This method will solve another issue, in which sometime there is 
possible to login without reading the profile file, causing 
HISTFILESIZE not read and the history file truncate to the 
default small size.

I'll let you know how it goes.

Thanks!

-- 
                              (stephan paul) Arif Sahari Wibowo
    _____  _____  _____  _____
   /____  /____/ /____/ /____
  _____/ /      /    / _____/      http://www.arifsaha.com/
Technical Details
Message-ID: <alpine.OSX.1.10.0809231112480.13605@imac2006.local>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!feeder1-2.proxad.net!proxad.net!feeder1-1.proxad.net!ecngs!feeder2.ecngs.de!87.106.137.111.MISMATCH!feeder1.news.weretis.net!newsfeeder.dynfx.net!weretis.net!newsfeed.datemas.de!feed.cnntp.org!news.cnntp.org!not-for-mail
References: <alpine.OSX.1.10.0809191320370.13605@imac2006.local> <2cwBk.63162$4F4.32442@newsfe24.ams2>

Show Full Headers
Complete Article Headers
X-Google-Thread: 1012a6,6f426515059a57b0
X-Google-Thread: 1054c0,6f426515059a57b0
X-Google-Attributes: gid1012a6,gid1054c0,domainid0,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!feeder1-2.proxad.net!proxad.net!feeder1-1.proxad.net!ecngs!feeder2.ecngs.de!87.106.137.111.MISMATCH!feeder1.news.weretis.net!newsfeeder.dynfx.net!weretis.net!newsfeed.datemas.de!feed.cnntp.org!news.cnntp.org!not-for-mail
Newsgroups: comp.unix.shell,gnu.bash
Date: Wed, 24 Sep 2008 09:43:15 -0400
From: S P Arif Sahari Wibowo <arifsaha@yahoo.com>
Subject: Re: bash history: saving to and restoring from different file
In-Reply-To: <2cwBk.63162$4F4.32442@newsfe24.ams2>
Message-ID: <alpine.OSX.1.10.0809231112480.13605@imac2006.local>
References: <alpine.OSX.1.10.0809191320370.13605@imac2006.local> <2cwBk.63162$4F4.32442@newsfe24.ams2>
User-Agent: Alpine 1.10 (OSX 962 2008-03-14)
X-Archive: encrypt
MIME-Version: 1.0
Content-Type: TEXT/PLAIN; format=flowed; charset=US-ASCII
Lines: 47
Organization: CNNTP
NNTP-Posting-Host: d84ee751.read.cnntp.org
X-Trace: DXC=7]4iCY\3PIP]7l7niOa`GPWoT\PAgXa?QNdYcLc48:AVBQ=;T6O1baUZ]dged6hbF\WCL;1A^C63\`lLFCDAeLgQ
X-Complaints-To: abuse@cnntp.org