Linux的!(感叹号)

时间:2021-01-02 10:56:08   收藏:0   阅读:0

echo "Hello World!" > index.html时发现会回显执行的命令,且index.html文件中没有!号
使用echo "Hello World\!" > index.html时发现连同\一起输出
解决办法,不使用双引号,改用单引号echo ‘Hello World!‘ > index.html
或者感叹号后添加空格echo "Hello World! " > index.html

出现这个问题并不是因为转义,而是感叹号还有特殊用法
!号用于执行历史命令
# history 1 ping www.baidu.com 2 ls 3 history
->可使用!1执行第一条命令
!1 ping www.baidu.com ...
->使用!-1或!!执行倒数第一条命令(因为上方!1执行了第一条命令,所以!-1还是ping www.baidu.com)
!-1 ping www.baidu.com ...
->使用!?s执行最近一次命令中包含s的命令
!?s ls ...
->使用!$代替上一个命令中的参数
ping -6 www.baidu.com ... ping !$ ping www.baidu.com ...

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!