5

I was trying to a string search within Ubuntu 12.04 which went as follows:

find . -exec grep -l "!45" {} \;

Instead of searching for the string "!45", it was replaced with top. It didn't invoke the commmand, but merely start searching for the term "top". Until I figured out -F for grep, I thought special characters would be treated as text in between quotations.

Anywho, now that I've discovered this, I have no idea what this is, what it's used for, or why it even exists!

1 Answers1

9

In the bash shell, !45 returns that command from the command history (or !32 or !873).

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.

!

Start a history substitution, except when followed by a space, tab, the end of the line, ‘=’ or ‘(’ (when the extglob shell option is enabled using the shopt builtin).

!n

Refer to command line n.

Check here for full details from the bash manual.

EightBitTony
  • 21,373