1

In bash:

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

But:

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

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

3
  • 1
    what were you expecting to happen ? the history would be "echo !!" (two exclamation marks)
    – Sirex
    Commented Feb 23, 2011 at 8:33
  • @Sirex Why in echo "!" expand and echo ! not expand?
    – osdyng
    Commented Feb 23, 2011 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
    Commented Feb 23, 2011 at 8:58

1 Answer 1

8

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).

2
  • why echo -e "!\n" and echo -e "!\r" expand?
    – osdyng
    Commented Feb 23, 2011 at 8:44
  • @osdyng because after bang followed slash
    – ooshro
    Commented Feb 23, 2011 at 8:54

You must log in to answer this question.

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