[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: history -f filename
From: |
Chet Ramey |
Subject: |
Re: history -f filename |
Date: |
Mon, 2 Dec 2024 12:26:15 -0800 |
User-agent: |
Mozilla Thunderbird |
On 11/30/24 9:36 PM, Dan Jacobson wrote:
$ history |wc - $HISTFILE|sed \$d
7622 75741 532254 -
14973 29625 320996 /home/jidanni/.bash_history_jidanni
Works as expected.
Sure. You have fewer in-memory history entries than in your history file,
which is kind of unusual, but not unheard of.
$ (a=~/.bash_history_jidanni-emacs; HISTFILE=$a history |wc - $a|sed \$d)
7625 75780 532531 - ### I expected to see about 1399/2 here.
1399 3535 35312 /home/jidanni/.bash_history_jidanni-emacs
We see for simple
$ history
output, there's no way to change the file it reads,
It doesn't read a file. After reading HISTFILE when the shell starts up,
the only thing changing HISTFILE does is to change where the shell writes
the history when it exits. You have to use the history options that read
and write files to import/export this in-memory list.
at least with the
current (same PID) shell.
This is just wrong. You can write a shell function and temporarily swap
history files to populate the in-memory list as much as you want without
forking a new shell.
"CR" == Chet Ramey <chet.ramey@case.edu> writes:
CR> Use `history -r'?
That would change files (by more than just one line).
I think there's a fundamental misunderstanding here about the in-memory
nature of the history list.
You can always generate a temp file name, write the current history to it,
read a new history file into memory, do what you want, optionally write it
back out, and then reload the history from the temporary file.
All I want is a read-only operation.
CR> Because those are the options that act on the history file. The rest act
CR> on the in-memory history list.
So maybe a new -f is needed:
$ history -f filename
to simply read from filename.
CR> What exactly would this do?
It would do just like plain
$ history
but instead of reading from the in memory list,
(which is about the same as $HISTFILE + or - one line)
It is not, unless you're doing something like syncing the history list to
the history file from $PROMPT_COMMAND. Look at your first example.
it would read from the given file.
Use a shell function as described above. But there's little difference
between that and `cat', unless you want to restrict the output to a
subset of the history file entries or take advantage of timestamps.
--
``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/
OpenPGP_signature.asc
Description: OpenPGP digital signature
- Re: history -f filename,
Chet Ramey <=