Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

In bash:

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

But:

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

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

share|improve this question
1  
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

1 Answer 1

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

Your Answer

 
discard

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.