#write to history file at each shell prompt
export PROMPT_COMMAND="history -a; history -c; history -r; $PROMPT_COMMAND"
#write to history file at each shell prompt
(Unless I read your comment wrong.)