linux 中printf命令输出感叹号!

发布时间 2023-06-22 17:53:39作者: 小鲨鱼2018

 

001、测试

[root@PC1 test01]# printf "abcd\n"          ## 输出abcd并换行
abcd
[root@PC1 test01]# printf "ab!cd\n"         ## 不能正常的输出感叹号
-bash: !cd\n": event not found
[root@PC1 test01]# printf "ab\!cd\n"        ## 加转义字符也不行
ab\!cd

 

002、正确做法

[root@PC1 test01]# printf "%s\n" abcd\!
abcd!
[root@PC1 test01]# printf "%s\n" ab\!cd       ## 利用printf命令输出感叹号
ab!cd

 

或者:

[root@PC1 test01]# printf "%s\n" 'ab!cd'
ab!cd