You are not logged in.

#1 2024-07-03 21:03:54

bhe69
Member
Registered: 2024-01-11
Posts: 13

Bash ignores erasedups

Hello,

I've taken the option "erasedups" from the Arch Wiki on Bash: https://wiki.archlinux.org/title/Bash#H … tomization
It should remove any duplicate entries in bash history. My current .bashrc looks like this (most of it is default, LANG and HISTCONTROL were added by me.

#
# ~/.bashrc
#

# If not running interactively, don't do anything
[[ $- != *i* ]] && return

alias ls='ls --color=auto'
alias grep='grep --color=auto'
PS1='[\u@\h \W]\$ '

# https://wiki.archlinux.org/title/Bash#History_customization
export HISTCONTROL="erasedups:ignorespace"

export LANG="en_US.UTF-8"

However my .bash_history still looks like this:

sudo pacman -Suy
yay -Suy
sudo pacman -Suy
yay -Suy
sudo pacman -Suy
yay -Suy
WINEPREFIX=~/wine winecfg 
cat .bashrc 
WINEPREFIX=~/wine winecfg 
sudo pacman -Suy
yay -Suy
cat .bashrc 
xed .bashrc 
sudo pacman -Suy

Why is bash ignoring the erasedups command? I'm using gnome-terminal, but that shouldn't make any difference. New commands are added to bash history, but duplicates never removed.

Offline

#2 2024-07-04 09:56:22

Lone_Wolf
Administrator
From: Netherlands, Europe
Registered: 2005-10-04
Posts: 15,083

Re: Bash ignores erasedups

You may be misunderstanding what that option does,

Try executing the same command 5 times in a row, then check how many times it is shown in history .


Disliking systemd intensely, but not satisfied with alternatives so focusing on taming systemd.

clean chroot building not flexible enough ?
Try clean chroot manager by graysky

Offline

#3 2024-07-04 20:35:33

bhe69
Member
Registered: 2024-01-11
Posts: 13

Re: Bash ignores erasedups

Lone_Wolf wrote:

You may be misunderstanding what that option does,

https://man.archlinux.org/man/bash.1#HISTCONTROL says:
A value of erasedups causes all previous lines matching the current line to be removed from the history list before that line is saved.
This is what I want: Remove previous identical lines from the history.

Try executing the same command 5 times in a row, then check how many times it is shown in history .

If I don't close the terminal it is show only once in history. If I close the terminal, it will appear once for each try.

xed .bash_history
sudo pacman -Suy
etc-update 
sudo etc-update 
xed .bash_history
xed .bash_history
xed .bash_history

Offline

#4 2024-07-04 20:43:51

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,456
Website

Re: Bash ignores erasedups

bhe69 wrote:

This is what I want: Remove previous identical lines from the history.

And that's what you're getting: they are removed from the active process history - but it does not edit the already archived HISTFILE content.  Though if you do not have histappend set, this file should get overwritten.  What's the output of `shopt | grep histappend`?

Last edited by Trilby (2024-07-04 20:46:36)


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#5 2024-07-05 21:59:44

bhe69
Member
Registered: 2024-01-11
Posts: 13

Re: Bash ignores erasedups

Trilby wrote:

Though if you do not have histappend set, this file should get overwritten.  What's the output of `shopt | grep histappend`?

histappend seems to be off.

$ shopt | grep histappend
histappend     	off

Offline

#6 2024-07-05 22:21:42

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,456
Website

Re: Bash ignores erasedups

Hmm, in that case it does seem to be not working as documented.


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

Board footer

Powered by FluxBB