简体   繁体   中英

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?

You can use single quotes:

echo 'Hello!'
Hello!

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

您可以使用set +H关闭历史记录扩展,并使用set -H重新启用它

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM