8

Running echo "Hello world!" in bash:

# echo "Hello world!"
-bash: !": event not found

Why does bash complain "!": event not found"? No !, everything is OK:

# echo "Hello world"
Hello world

Update: My bash version:

# bash --version
GNU bash, version 4.2.46(1)-release (x86_64-redhat-linux-gnu)
2
  • Which version of bash is this? On my 4.3.11 it doesn't give that message and just echos the content of the double quoted string (the quotes enough to remove the special meaning of !)
    – Anthon
    Apr 18, 2016 at 6:47
  • @Anthon: 4.2.46, thanks!
    – Nan Xiao
    Apr 18, 2016 at 6:51

1 Answer 1

14

Because ! is a reserved word in bash.

The most common uses are to negate stuff and to access the last command, but it can be used for a few different things, so the best advise is check the man page, and use single quotes (i.e. ''s) around strings that doesn't need expansion.

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