Xiphias
Xiphias

Reputation: 4716

Why can I not use an exclamation mark in bash' echo, not even when it is escaped?

My question is simple:

$ echo "Hello!"
sh: !": event not found

What is ! in this case? I then tried echo "Match\!", but that resolves to Match\!. How do I have to write the statement?

Upvotes: 8

Views: 2761

Answers (2)

glenn jackman
glenn jackman

Reputation: 246807

You can turn off history expansion with set +H and re-enable it with set -H

Upvotes: 3

anubhava
anubhava

Reputation: 785128

You can use single quotes:

echo 'Hello!'
Hello!

Otherwise in double quotes shell attempts to expand ! to an event from the history..

Upvotes: 13

Related Questions