Skip to main content
8 of 9
When using the export command some strange behaviour occurs. Specifically, try running `bash` to reload the configuration file, then `echo $PROMPT_COMMAND`. The $PROMPT_COMMAND variable becomes n copies of this command when export is used!! Not good. The answer also does not specify why export

Add the following to ~/.bashrc

# Avoid duplicates
HISTCONTROL=ignoredups:erasedups  
# When the shell exits, append to the history file instead of overwriting it
shopt -s histappend

# After each command, append to the history file and reread it
PROMPT_COMMAND="${PROMPT_COMMAND:+$PROMPT_COMMAND$'\n'}history -a; history -c; history -r"
Pablo R.
  • 4.8k
  • 1
  • 17
  • 2