🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.unix.shell
Article #4024

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

#4024
From: Chris F.A. Johnson
Date: Sun, 21 Sep 2008 00:00
30 lines
2146 bytes
On 2008-09-20, S P Arif Sahari Wibowo wrote:
>
> Is there a way for an interactive bash invocation to restore 
> history from file A, but later save / append to file B?
>
> As for the motivation, it is to reduce duplicate in restored 
> history, therefore can fit more lines in the history without 
> increasing memory per bash invocation. Yes there is erasedups 
> HISTCONTROL option but it does not help removing duplicate 
> caused by multiple bash invocation. If the file to restore from 
> and file to save to can be different, I can create short script 
> to filter out the duplicate from the history file and save it in 
> different file. The bash invocation then restore history from 
> the filtered file but later still save / append added history to 
> the original history file.

hfile1=.bash_history
hfile2=.bash_history2

In your ~/.bashrc:

history -c -r "$hfile1"
history "$hfile2"


-- 
   Chris F.A. Johnson, author       <http://cfaj.freeshell.org/shell/>
   Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
   ===== My code in this post, if any, assumes the POSIX locale
   ===== and is released under the GNU General Public Licence
Technical Details
Message-ID: <c9cc6$48d58e97$cef88ba3$32079@TEKSAVVY.COM>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!out04a.usenetserver.com!news.usenetserver.com!in04.usenetserver.com!news.usenetserver.com!uns-out.usenetserver.com!news.usenetserver.com!pc03.usenetserver.com!TEKSAVVY.COM-a2kHrUvQQWlmc!not-for-mail
References: <alpine.OSX.1.10.0809191320370.13605@imac2006.local>

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!g2news1.google.com!news4.google.com!out04a.usenetserver.com!news.usenetserver.com!in04.usenetserver.com!news.usenetserver.com!uns-out.usenetserver.com!news.usenetserver.com!pc03.usenetserver.com!TEKSAVVY.COM-a2kHrUvQQWlmc!not-for-mail
Newsgroups: comp.unix.shell,gnu.bash
From: "Chris F.A. Johnson" <cfajohnson@gmail.com>
Subject: Re: bash history: saving to and restoring from different file
References: <alpine.OSX.1.10.0809191320370.13605@imac2006.local>
Reply-To: cfajohnson@gmail.com
User-Agent: slrn/0.9.8.1 (Linux)
Message-ID: <c9cc6$48d58e97$cef88ba3$32079@TEKSAVVY.COM>
X-Complaints-To: abuse@usenetserver.com
Organization: UseNetServer.com
Date: Sun, 21 Sep 2008 00:00:23 +0000
Lines: 30
X-Trace: c9cc648d58e976b5d2e0632079