HISTCONTROL=ignoreboth doesn't work [duplicate]
It's working as intended. ignoredups
, implied by ignoreboth
, doesn't add a command to history if it's the same as the immediate previous command. It doesn't look further back in history. From the manual:
A value of ‘
ignoredups
’ causes lines which match the previous history entry to not be saved.
So, this will add foo
twice to the history:
$ foo
$ bar
$ foo
But so will this:
$ foo
$ bar
$ foo
$ foo
The last foo
won't be added to history, since the previous command was foo
. Use erasedups
in conjunction:
A value of ‘
erasedups
’ causes all previous lines matching the current line to be removed from the history list before that line is saved.
So:
HISTCONTROL=ignoreboth:erasedups