linux 中 在终端命令行如何输出!号

 

001、问题 shell终端下,双引号内输出!报错

[root@pc1 test1]# echo "hello world!"
-bash: !": event not found

 

002、问题原因

终端中! 表示执行历史命令。

 

003、解决方法

a、使用单引号

[root@pc1 test1]# echo 'hello world!'    ## 使用单引号
hello world!

 

b、修改环境变量

[root@pc1 test1]# echo $-
himBH
[root@pc1 test1]# set +H             ## 修改环境变量
[root@pc1 test1]# echo "hello world!"
hello world!

 。

 

c、将!放在双引号外

[root@pc1 test1]# echo "hello world"!     ## 将!放在双引号外
hello world!

 。

 

posted @ 2024-02-20 14:48  小鲨鱼2018  阅读(7)  评论(0编辑  收藏  举报