$(history -p \!\!)
is a way of getting the last command executed without adding it again to the history. From help history
:
-p perform history expansion on each ARG and display the result
without storing it in the history list
In bash, !!
expands to the last command executed, but you cannot directly use this in aliases, since this expansion is performed well before alias expansion. (History expansion is one of the earliest to happen - it happens before even brace expansion (which is usually first).)
So, you have to use some way to get the last command executed, and that can be done using history -p
, which expands !!
the way the shell would.
Though I don't know why they escaped !
. For me, it works fine without the backslashes.
sudo !!
doesn't work and how to write a more robust alias – Gilles 'SO- stop being evil' Jan 13 '15 at 22:50