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)
Nan Xiao
  • 1,407
  • 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 '16 at 06:47
  • @Anthon: 4.2.46, thanks! – Nan Xiao Apr 18 '16 at 06:51

1 Answers1

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.