Take the 2-minute tour ×

In bash:

$ a=1
$ echo $a
$ echo "$a"


$ echo !
$ echo "!"
bash: !: event not found

Why in "echo !", bash don't expand.

share|improve this question
what were you expecting to happen ? the history would be "echo !!" (two exclamation marks) –  Sirex Feb 23 '11 at 8:33
@Sirex Why in echo "!" expand and echo ! not expand? –  osdyng Feb 23 '11 at 8:34
What do you expect it to expand into? As Sirex has said, for the last command, it's "!!", and as ooshro has said, a single "!" indicates to the shell that more will follow to inform the expansion. Unless you give bash another character to say what you're trying to select from the history, it'll fail, as it is indeed failing. –  MadHatter Feb 23 '11 at 8:58
add comment

1 Answer

up vote 7 down vote accepted

In "echo !", after bang followed the carriage return.

man bash

! Start a history substitution, except when followed by a blank, newline, carriage return, = or ( (when the extglob shell option is enabled using the shopt builtin).

share|improve this answer
why echo -e "!\n" and echo -e "!\r" expand? –  osdyng Feb 23 '11 at 8:44
@osdyng because after bang followed slash –  ooshro Feb 23 '11 at 8:54
add comment

Your Answer


