Bash – sharing or synchronizing history between Zsh and Bash

bashcommand historysynchronizationzsh

I often find myself switching between Bash and Zsh, and using the history search functionality to recover a command.

However, since Bash and Zsh have different history files, I often find that the command I'm searching for has been executed in the other shell.

Is there any way to share or synchronize history between the two?

Best Answer

If you are using the defaults for bash and zsh:

$ cat ~/.histfile >> ~/.bash_history
$ youreditor ~/.zshrc
# Here change your config to:
HISTFILE=~/.bash_history
$ rm ~/.histfile

Now you have the same file for history in both shells.