日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > linux >内容正文

linux

linux命令行中,双引号中的感叹号将被解释为历史命令

發布時間:2025/4/5 linux 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 linux命令行中,双引号中的感叹号将被解释为历史命令 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

linux命令行中,雙引號中的感嘆號將被解釋為歷史命令。

命令:

test -e ttt/ && echo "file exist!" || echo "file Not exist!"

輸出:

bash: !": event not found
命令:

test -e ttt/ && echo "file exist" || echo "file Not exist"
輸出:

file exist


實驗如下:

arthur@E430 ~/workspace/test]$ls bin HelloWorld.class HelloWorld.java re t2.sh t.sh d HelloWorld.jar HelloWorld.java~ t1.sh t.py [arthur@E430 ~/workspace/test]$echo "!!" echo "ls " ls [arthur@E430 ~/workspace/test]$pwd /home/arthur/workspace/test [arthur@E430 ~/workspace/test]$echo "!l" echo "ls " ls? [arthur@E430 ~/workspace/test]$echo "!!" echo "echo "ls "" echo ls? [arthur@E430 ~/workspace/test]$echo "!!" echo "echo "echo "ls """ echo echo ls? [arthur@E430 ~/workspace/test]$

如果是想要輸出感嘆號,可以:

1. 使用單引號。

一般要輸出特殊符號,可以用單引號'引文',或者\。 這時候最好用單引號,如: echo 'Hello World !'比如要輸出That's good.就用 echo "That's good."

2.?

\! 表示感嘆號 比如echo Hello\ World\ \!, linux很多符號都是用轉義符"\"來表示的,盡量不要用雙引號“”。 原因你自己 echo "Hello World !",就會發現輸出錯誤的, 而 echo "Hello World \!",又發現連“\”也一起輸出了





查資料如下:




在雙引號中,感嘆號(!)的含義根據使用的場合有所不同,在命令行環境,它將被解釋為一個歷史命令,而在腳本中,則不會有特殊含義。

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 ~]#

?

在腳本中使用感嘆號,將不會進行歷史擴展。

總結

以上是生活随笔為你收集整理的linux命令行中,双引号中的感叹号将被解释为历史命令的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。