Every now and then it would be useful to add a command directly to the history in Bash without actually executing it. So far the closed thing I have found is adding a
# in front of it and hitting return. Are there better ways?
You can even bind a keystroke to do this for you. You can enter this at a Bash prompt:
or add this to your
then you can type something and press Ctrl-q and it will be added to the history without being executed. The space before "history" causes the
It is hard to come up with anything shorter than a one character "command", so we really need to go to the keystroke level. With my bash setup and an US keyboard what you do now takes:
so in total 3 instructions, 5 keypresses.
Using ALT# does the same in 1 instruction, 2 keypresses.
YMMV depending on your keyboard layout and bash configuration.