How do I add a command to bash history without executing it?

Just use history -s arg.

-s The args are added to the end of the history list as a single entry.

http://ss64.com/bash/history.html


As an alternative to editing the history you could use Ctrl-U to cut the line (note that this cuts backward from the cursor, so it should be at the end), and Ctrl-Y to paste it back later. Meta-Y used after Ctrl-Y will cycle through the different cut values so you can get back to previous ones as well.


Another alternative is to put a hash at the front of the line:

# echo this command will not execute, but it will be in the history.

You can edit the ~/.bash_history file.

Tags:

Bash