-2

Why does the Bash setting on duplication affairs not work? In .bashrc:

export HISTCONTROL=erasedups:ignoredups

It keeps recording ie. writing every command typed in CLI into .bash_history

EDIT :
That practical input is of any kind not just hand typing, but also of command history retrieval
@icarus advice is taken, as to get PROMPT_COMMAND variable cleaned up, but see the effect later in quite time
So confusing.. so please help out clarify the nitty gritty works

3
  • 1
    Works for me (GNU bash, version 5.2.26(1)-release). Can you provide a repeatable example in your question illustrating the issue? Commented Aug 10, 2024 at 9:44
  • 1
    Do you have PROMPT_COMMAND set? If so it might be updating your history file. Commented Aug 10, 2024 at 10:07
  • 1
    Are the lines added to the history file immediately or only when you exit the shell? In other words if you run "bash" inside the bash prompt to start a new shell, run "echo test" to run a command, run "tail ~/.bash_history" to see the last few lines of the history do you see the "echo test" or not. run "exit" to get out of the subshell, and then run "tail ~/.bash_history" and you should expect to see the "echo test". Commented Aug 10, 2024 at 17:53

1 Answer 1

1

First the man page of bash 5.2

HISTCONTROL

    A colon-separated list of values controlling how commands
    are saved  on  the history list.  If the list  of  values
    includes  ignorespace, 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 short-
    hand for ignorespace and ignoredups.  A value  of  erase-
    dups 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.

From this we can conclude that erasedups and ignoredups are mutually exclusive.

"erasedups" erases older entries of a duplicate command and makes a new entry. "ignoredups" keeps the older entry and makes no new entry

Only 4 settings are defined

erasedups
ignorespace
ignoredups
ignoreboth

The only useful combination would be

erasedups:ignorespace

since

ignoredups:ignorespace

is the same as

ignoreboth

Now reality

I test this with bash 5.2.21. For me ignoredups seem to have no effect as every command is recorded, erasedups does what the manpage says.

Your combination (erasedups:ignoredups) does the same as only specifying erasedups. In your case there seem to be no effect. I can't explain this discrepancy.

I wonder if the documentation in the man page is wrong? Does ignoredups really mean "allow dupes"? Either that or a bug in bash it seems.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.