Linux Shell 中的反引號,單引號,雙引號

2021-07-13 12:24:08 字數 834 閱讀 4532

反引號位 (`) 位於鍵盤的tab鍵的上方、1鍵的左方。注意與單引號(')位於enter鍵的左方的區別。

在linux中起著命令替換的作用。命令替換是指shell能夠將乙個命令的標準輸出插在乙個命令列中任何位置。

如下,shell會執行反引號中的date命令,把結果插入到echo命令顯示的內容中。

[root@localhost sh]# echo the date is `date`

the date is 2023年 03月 14日 星期一 21:15:43 cst

單引號、雙引號用於使用者把帶有空格的字串賦值給變數事的分界符。

[root@localhost sh]# str="today is monday"

[root@localhost sh]# echo $str

today is monday

如果沒有單引號或雙引號,shell會把空格後的字串解釋為命令。

[root@localhost sh]# str=today is monday

bash: is: command not found

單引號和雙引號的區別。單引號告訴shell忽略所有特殊字元,而雙引號忽略大多數,但不包括$、\、`。

[root@localhost sh]# testvalue=100

[root@localhost sh]# echo 'the testvalue is $testvalue'

the testvalue is $testvalue

[root@localhost sh]# echo "the testvalue is $testvalue"

the testvalue is 100

Linux SHELL指令碼中的反引號

linux shell指令碼中的反引號 用反引號,將shell命令引起來,可以將命令的輸出值賦給變數 比如這裡,date命令輸出具體的時間 root localhost date mon apr 27 16 07 01 cst 2020那麼我用反引號將命令完整的引起來,賦值給變數today,那我們可...

Linux Shell 中的反引號,單引號,雙引號

反引號位 位於鍵盤的tab鍵的上方 1鍵的左方。注意與單引號 位於enter鍵的左方的區別。在linux中起著命令替換的作用。命令替換是指shell能夠將乙個命令的標準輸出插在乙個命令列中任何位置。如下,shell會執行反引號中的date命令,把結果插入到echo命令顯示的內容中。root loca...

Linux Shell 中的反引號,單引號,雙引號

反引號位 位於鍵盤的tab鍵的上方 1鍵的左方。注意與單引號 位於enter鍵的左方的區別。反引號在linux中起著命令替換的作用。命令替換是指shell能夠將乙個命令的標準輸出插在乙個命令列中任何位置。root localhost sh echo the date is date root loc...