In Bash, I'd like to create a binding in my .inputrc
that makes use of the !!
built-in to repeat the last command. But this doesn’t seem to properly expand the !!
bind -x '"\C-t": echo $(!!)'
When I invoke the above binding (Ctrl+t) I just get this:
-bash: !!: command not found
Likewise the simpler
bind -x '"\C-t": echo !!'
Just yields
!!
Instead of the actual command. Obviously my real use-case is more substantive than this example, this is just an illustration of the problem.
Edit:
This question has nothing to do with echo "#!" fails -- "event not found" which it is claimed mine is a duplicate of. That question pertains to a generalized failure of !*
expansion in regular bash due to quoting issues or lack of history. My question on the other hand is very specific to the context of being used inside an .inputrc
file (or perhaps an alias), where a different set of factors come into play. On my regular command line, the so-called "bang expansions" have always worked fine. It's only in these special contexts where the problems arose, and hence led to this question.