I am trying to write a bash function in my .bashrc
that reruns the previous command in the history and does something useful with the captured output.
my_function() {
output=$(!!)
# Do something with output
}
I am getting: bash: !!: command not found
. I understand there is a difference between commands and shell builtins, but can't figure out how to run this builtin from a function, or its command equivalent, if it even exists. How can I rerun the previous shell command from within a bash function?