[Top][All Lists]

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

Command history with several shell instances

From: Michael Siegel
Subject: Command history with several shell instances
Date: Sun, 8 Dec 2019 12:11:44 +0100
User-agent: Mozilla/5.0 (X11; Linux i686; rv:68.0) Gecko/20100101 Thunderbird/68.2.2


I have a question on how Bash handles preserving the command history in
~/.bash_history when several shell instances are used in parallel. I was
expecting the history file to be overwritten every time a shell instance
is terminated because bash(1) says:

If the histappend shell option is enabled (see the description of shopt
under SHELL BUILTIN COMMANDS below), the lines are appended to the
history file, otherwise the history file is overwritten.

However, this doesn't seem to be the case even though `shopt | grep
histappend` gives me "histappend off" on both systems I have tested this
on, which are Devuan running Bash 4.4.12 and Void Linux running Bash 5.0.11.

The following is a record of the test I ran using three terminal
emulator windows under X. (I also ran this on TTYs on Void Linux.)


Open window "Alice" and run:

  rm ~/.bash_history && history -c && clear

Then open window "Bob". Both shell instances now have no command history.

In window "Alice", run:

  echo BSD

Now "echo BSD" is in the "Alice" session's command history, but, as
expected, "Bob" knows nothing about it.

Close window "Alice", which will write out the "Alice" session's command
history to ~/.bash_history (creating the file because it doesn't exist).

Now, in window "Bob", look at ~/.bash_history:

  $ cat ~/.bash_history
  echo BSD

In window "Bob" run:

  echo Linux

Now "cat ~/.bash_history" and "echo Linux" are in the "Bob" session's
command history.

Close window "Bob".

Expected outcome: Content of ~/.bash_history from session "Alice" is
overwritten with command history of session "Bob" because histappend is

Open new window "Charlie" and look at ~/.bash_history:

  $ cat .bash_history
  echo BSD
  cat ~/.bash_history
  echo Linux


I mean, it's nice that it works that way and the history is not simply
overwritten. That's what I'd want anyway. It's just that I fail to see
how this is not contradicting what is stated in the manual page.


reply via email to

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