Wednesday, May 1, 2024
148
rated 0 times [  148] [ 0]  / answers: 1 / hits: 119679  / 3 Years ago, mon, october 18, 2021, 1:13:05

I use mainly Terminator, and it's usually opened with 3 split terminal windows. I also use Gnome terminal for various reasons.

I'm wondering how is bash history handled in this case as I sometimes miss previously issued commands when I run history



For example, my prompt shows current bash history line (!) and if I launch Terminator with 3 split terminal windows I get same history line (let's say 100) on all terminals. Which history will be saved?



Also launching Gnome Terminal after using Terminator I get line 100 at startup regardless all commands issued before in Terminator


More From » command-line

 Answers
2

The bash session that is saved is the one for the terminal that is closed the latest. If you want to save the commands for every session, you could use the trick explained here.



export PROMPT_COMMAND='history -a'

To quote the manpage: “If set, the value is executed as a command prior to issuing each primary prompt.”


So every time my command has finished, it appends the unwritten history item to ~/.bash_history before displaying the prompt (only $PS1) again.


So after putting that line in /etc/bash.bashrc I don’t have to find myself reinventing wheels or lose valuable seconds re-typing stuff just because I was lazy with my terminals.



Anyway, you'll need to take into account that commands from different sessions will be mixed in your history file so it won't be so straightforward to read it later.


See also:



[#41983] Tuesday, October 19, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
tionverflow

Total Points: 500
Total Questions: 115
Total Answers: 120

Location: Northern Ireland
Member since Mon, Nov 14, 2022
1 Year ago
;