I wanted to test something in shell and I've typed echo "!!" instead of typical echo "foo".

I didn't get the !! for output. Instead, (and very unexpectedly!) it produced the output of my previous command issued for Bash.

I tried to google the phrases bash !! (and permutations like bash +"!!"), but I couldn't find any reference for this feature.

Can someone tell me something about the exclamation marks' stuff and Bash? At least how to find extra info?

I use Bash 4.2.45 on Linux Mint 16 64 bit.

  • This did not just produce the output from the previous command (out of some cache), it actually runs the previous command.
    – Zelda
    Commented Feb 9, 2014 at 11:06
  • @Zelda No, it doesn't execute the last command, it just inserts it. !! alone on a line will execute the last command, while echo "!!" will just echo the last command.
    – RalfFriedl
    Commented Sep 26, 2018 at 5:19

2 Answers 2


From man bash, section HISTORY EXPANSION:

Event Designators

An event designator is a reference to a command line entry in the history list. Unless the reference is absolute, events are relative to the current position in the history list.


!! - Refer to the previous command. This is a synonym for `!-1'

You can turn history expansion off with set +H if you don't like it. I generally prefer to use readline to do history lookups instead.


You just need to put the exclamation marks between single quotes.

$ echo '!!'

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .