2

HISTCMD displays an erratic behaviour, though I never reset it I promise (I checked all my configuration files). As a result I cannot delete the entry containing my password which I inadvertently typed before the prompt. "history -c" apparently did nothing.

alex@Freesia:~$ echo $HISTCMD
916352
alex@Freesia:~$ echo $HISTCMD
931399
alex@Freesia:~$ history | tail
[...]
946443  2020-10-30-12:55history -d 871209
946444  2020-10-30-12:55history | tail
946445  2020-10-30-12:56echo $HISTCMD
946446  2020-10-30-12:56history | tail
alex@Freesia:~$ history -d 946444
bash: history: 946444: history position out of range

My HIST variables:

alex@Freesia:~$ env | grep HIST
HISTIGNORE=?:??
HISTCONTROL=ignoreboth
HISTTIMEFORMAT=%Y-%m-%d-%H:%M
HISTSIZE=2000
HISTFILESIZE=15000

Linux Freesia 4.9.0-13-amd64 #1 SMP Debian 4.9.228-1 (2020-07-05) x86_64 GNU/Linux

Quasímodo
  • 18,625
  • 3
  • 35
  • 72
  • 1
    Alexandre, do you have your `PROMPT_COMMAND` set to something? As for deleting, why don't you just edit `$HISTFILE` manually and remove the offending line? – terdon Oct 30 '20 at 12:28
  • @LinuxSecurityFreak I would guess you just don't set them, so they don't appear in `env`. – terdon Oct 30 '20 at 12:29
  • @LinuxSecurityFreak I don't know. You might want to open a new question. If you have them in `~/.bashrc` then they should appear in `env` unless you're not actually using bash or you are not in an interactive, non-login shell. Personally, I set them in `~/.profile` since [I want them to affect all of my shell sessions](https://superuser.com/a/183980/151431) but `~/.bashrc` should also work. – terdon Oct 30 '20 at 13:02
  • 1
    It's the same problem pattern with [here](https://unix.stackexchange.com/questions/463017/history-c-does-not-reset-histcmd-to-1) for every command typed, `HISTCMD` increases by a constant number a bit higher than `HISTFILESIZE`, (15047 here). Also, follow the links from this post. Is this about `PROMPT_COMMAND` ? – thanasisp Oct 30 '20 at 14:16
  • @terdon Thanks! I remember having fiddled with an "eternal history" procedure a long time ago. I still had PROMPT_COMMAND="history -a;history -r" – Alexandre Oberlin Oct 30 '20 at 14:26

1 Answers1

1

As suggested by @terdon, PROMPT_COMMAND was the culprit. After having unexpectedly lost a few command lines, I once had implemented an "eternal history" procedure using the instructions found in https://debian-administration.org/article/543/Bash_eternal_history. I eventually stopped using this approach but I might have broken it while experimenting, since I still had

PROMPT_COMMAND="history -a;history -r" 

which is not exactly what the above page recommends.