Bash – How to stop bash editing the history when I reuse and modify an entry

bashcommand historyline-editor

Some instances of bash change the command history when you re-use and edit a previous command, others apparently don't. I've been searching and searching but can't find anything that says how to prevent commands in the history from being modified when they're reused and edited.

There are questions like this one, but that seems to say how to cope with the history being edited. I've only recently come across an instance of bash that does edit the history when you reuse a command – all previous bash shells I've used have (as far as I've noticed) been configured not to change the history when you reuse and edit a command. (Perhaps I've just not been paying proper attention to my shell history for the past 15 years or so…)

So that's probably the best question: CAN I tell bash NEVER to modify the history – and if so, how?

Best Answer

Turns out revert-all-at-newline is the answer. I needed to include set revert-all-at-newline on in my ~/.inputrc file, since using the set command at the bash prompt had no effect. (Then, of course, I had to start a new shell.)

Also, I found that ~/.inputrc is loaded instead of /etc/inputrc if present, which means that any defaults defined in the latter are no longer active when you create ~/.inputrc. To fix this, start ~/.inputrc with $include /etc/inputrc.

Thanks to @StéphaneChazelas for pointing me in the right direction.

Related Question