Bash history loss when using histappend

Sorry to answer my own question, but none of the other answers really address the problem.

I've finally figured out that this only happens when closing gnome-terminal itself (i.e. file > exit, the 'x' button, alt+F4), and even then generally only when closing several terminals in quick succession. It never happens when using ctrl-D to close the shell, letting the terminal follow.

If I can pin it down well enough, I'll file a gnome-terminal bug report. In the meantime, perhaps this will help some other people who get here from google!


No idea why this happens, but maybe you can circumvent the problem by forcing bash to write to its history file each time it displays a prompt:

PROMPT_COMMAND="history -a; history -n"

This will write (-a) and then re-read (-n) the history file each time bash prompts for the next command. Additional benefit: you'll get command X in shell 1 in the history of shell 2.