My .bashrc
contains the following:
HISTSIZE=30000
PROMPT_COMMAND="history -a"
export HISTSIZE PROMPT_COMMAND
What I notice:
- the
.bash_history
does get appended. - history on a given terminal session does not include entries appended from other terminal sessions
The desired behavior is to have the .bash_history
reloaded after any command on any terminal. What is the way to achieve this? Presumably it would be a modification to the PROMPT_COMMAND
?
Best Answer
The
history -a
command only appends to the history file. This doesn't affect any shell session unless you also read from it. So, what you're looking for is:As explained in
help history
:This way, you will first append your current shell's history to
$HISTFILE
and then read from it, importing the history appended from any other shell instance into the current one.Note that if you run a command in one terminal, it won't appear in the history of another until you run a command in the second. The
$PROMPT_COMMAND
is run before a prompt is shown, so if the second terminal is just open and sitting there, it won't read the new command run in the first one until you run something in the second and a new prompt is shown.