By pressing up, I can go through previously entered commands. I've noticed though that if I modify one of them, that alters the history. For instance, if I type:
echo a
echo b
echo c
[up][up][backspace]d[ctrl+c]
the history now shows that the second command was echo d
, not echo b
. How do I keep the first echo b
in the history?
For instance, say I run a really long command, with a lot of options. then I want to run it again, with a minor change, so I go back through the history to find it, make the change, but then realize that actually I don't need to re-run it, having just thought of another option to do instead. then later, I want to go back and remind myself what the command I ran was – but wait, the history is now showing the wrong thing!
This comes up very rarely, but when it does I find it really irritating. Is there some way to automatically preserve the original history?
Best Answer
Try to put in your
~/.inputrc
In some case you can find it in the default value (Off).
It should force
readline
to undo all changes to history lines before returning whenaccept-line
is executed. (more info inman bash
).Edit:
CTRL+c
andset revert-all-at-newline on
works fine sincebash-4.3.30
.But: