linux命令行中,双引号中的感叹号将被解释为历史命令。
命令:
test -e ttt/ && echo “file exist!” || echo “file Not exist!”
输出:
test -e ttt/ && echo “file exist” || echo “file Not exist”
file exist
查资料如下:
在双引号中,感叹号(!)的含义根据使用的场合有所不同,在命令行环境,它将被解释为一个历史命令,而在脚本中,则不会有特殊含义。
Advanced Bash-Scripting Guide: 5.1. Quoting Variables 写道Encapsulating “!” within double quotes gives an error when used from the command line. This is interpreted as a history command. Within a script, though, this problem does not occur, since the Bash history mechanism is disabled then.
在命令行环境,感叹号(!)称之为“历史扩展字符(the history expansion character)”。
[root@jfht ~]# pwd
/root
[root@jfht ~]# echo “!”
-bash: !: event not found
[root@jfht ~]# echo “!pwd”
echo “pwd”
pwd
[root@jfht ~]#
在脚本中使用感叹号,将不会进行历史扩展。
参考资料:
http://codingstandards.iteye.com/blog/1166282
在双引号中,感叹号(!)的含义根据使用的场合有所不同,在命令行环境,它将被解释为一个历史命令,而在脚本中,则不会有特殊含义。
Advanced Bash-Scripting Guide: 5.1. Quoting Variables 写道Encapsulating “!” within double quotes gives an error when used from the command line. This is interpreted as a history command. Within a script, though, this problem does not occur, since the Bash history mechanism is disabled then.
在命令行环境,感叹号(!)称之为“历史扩展字符(the history expansion character)”。
[root@jfht ~]# pwd
/root
[root@jfht ~]# echo “!”
-bash: !: event not found
[root@jfht ~]# echo “!pwd”
echo “pwd”
pwd
[root@jfht ~]#
在脚本中使用感叹号,将不会进行历史扩展。