Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
up vote 8 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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.