The Stage
sam@x230:~$ grep -E '^VERSION=|^NAME=' /etc/os-release
NAME="Ubuntu"
VERSION="20.04.5 LTS (Focal Fossa)"
sam@x230:~$ echo ${BASH_VERSINFO[@]}
5 0 17 1 release x86_64-pc-linux-gnu
sam@x230:~$ tail -n $HISTSIZE ~/.bash_history |grep '^ssh-add -l$' |wc -l
10
sam@x230:~$ grep -i hist .bashrc |egrep -v '^alias|^\s*#'
HISTCONTROL=ignoreboth
shopt -s histappend
HISTSIZE=1000
HISTFILESIZE=20000
sam@x230:~$ sed 's/\(ignoreboth\)$/\1:erasedups/' ~/.bashrc
sam@x230:~$ grep HISTCONTROL ~/.bashrc
HISTCONTROL=ignoreboth:erasedups
sam@x230:~$ export HISTCONTROL=ignoreboth:erasedups
sam@x230:~$ set |grep HIST
HISTCONTROL=ignoreboth:erasedups
HISTFILE=/home/sam/.bash_history
HISTFILESIZE=20000
HISTSIZE=1000
Scene 1:
sam@x230:~$ echo $HISTCONTROL
ignoreboth:erasedups
sam@x230:~$ ssh-add -l
256 SHA256:5FGaVpklzgSA1r/X8lb4SFaZ9hN0OfQXy+HOWpidcs4 default.sam@x230 (ED25519)
sam@x230:~$ tail -n $HISTSIZE ~/.bash_history |grep '^ssh-add -l$' |wc -l
10
sam@x230:~$ exit
Tragic ending, in a new terminal:
sam@x230:~$ echo $HISTCONTROL
ignoreboth:erasedups
sam@x230:~$ tail -n $HISTSIZE ~/.bash_history |grep '^ssh-add -l$' |wc -l
11
The experts
According to the man bash
:
HISTCONTROL
A colon-separated list of values controlling how commands are
saved on the history list. If the list of values includes ig‐
norespace, lines which begin with a space character are not
saved in the history list. A value of ignoredups causes lines
matching the previous history entry to not be saved. A value of
ignoreboth is shorthand for ignorespace and ignoredups. A value
of erasedups causes all previous lines matching the current line
to be removed from the history list before that line is saved.
Any value not in the above list is ignored. If HISTCONTROL is
unset, or does not include a valid value, all lines read by the
shell parser are saved on the history list, subject to the value
of HISTIGNORE. The second and subsequent lines of a multi-line
compound command are not tested, and are added to the history
regardless of the value of HISTCONTROL.
The critics
I expected that the last $HISTSIZE
lines of my bash history will no longer contain duplicates (over multiple cycles of starting and exit
of bash
).
Where am I going wrong in my actions or my assumptions?
Note: I also tried with setting HISTCONTROL=erasedups
, and the result is similar, i.e. duplicates remain (didn't test consecutive duplicates).
HISTCONTROL
only toerasedups
? And which version ofbash
do you use, on which OS/distro? – aviro Nov 27 '22 at 07:47erasedups
. Much thanks pointing out the missing info :) – Samveen Nov 27 '22 at 11:35