Save command to history without executing in bash
Use the -s
option to the history
command:
history -s cmd arg1 arg2
The call to history -s
itself, conveniently, is not added to the command history, so in your history it appears as if you executed cmd
without actually doing so.
There may be a better way, but you can use history expansion's :p
modifier to print the current comment line without executing. !#
is the current line, and %
by itself will match nothing
$ cmd [arguments] !#%:p