bash history and a lot of terminals

If you are using many terminals you know the problem, that the bash_history is only written after logging out. So if you want to share commands between two terminals you have to copy and paste them.

Reading the bash man page i found the PROMPT_COMMAND:

    If set, the value is executed as a command prior to issuing each primary prompt.

With this little guy it’s easy. Simple write this to your .bashrc and commands will be written directly to your history:

export PROMPT_COMMAND='history -a'

Leave a Reply

Your email address will not be published. Required fields are marked *