Because it seems often the history isn't saved when shutting down and not closing gnome terminal, I'd like to append to bash history before showing the prompt if the line isn't a duplicate. Although I have export HISTCONTROL=ignoreboth in bashrc, which is supposed to imply ignoredups, it doesn't seem to work, as I still get duplicates in bash_history. So how to do this?
To offer further indications, although not solutions:
I think $PROMPT_COMMAND needs to have "$(history 1)" (if_not_duplicate) >> ~/.bash_history
And this would remove non-adjacent duplicates, if they are already inserted.
perl -nei '$H{$_}++ or print' ~/.bash_history
ignoredupsonly removes immediate duplicates - That is, if you run the same command more than once without running any other commands in between, it's only registered once. It doesn't check the entire history for duplicates. – l0b0 Apr 30 '12 at 13:46