shell中的單引號 雙引號和反引號

2021-07-02 05:08:46 字數 1307 閱讀 2083

單引號:所有轉移符全部關閉,完整的反應括號中的內容

雙引號:部分轉義符關閉,但某些則保留(如:$ )

反引號:反引號內作為乙個系統命令並執行

(1)反引號位 (`) 位於鍵盤的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

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

[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

(3)單引號和雙引號的區別。單引號告訴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

shell中單引號 雙引號 反引號

一 單引號和雙引號 首先,單引號和雙引號,都是為了解決中間有空格的問題。因為空格在linux中時作為乙個很典型的分隔符,比如string1 this is astring,這樣執行就會報錯。為了避免這個問題,因此就產生了單引號和雙引號。他們的區別在於,單引號將剝奪其中的所有字元的特殊含義,而雙引號中...

shell中的單引號 雙引號 反引號

在shell中引號分為三種 單引號,雙引號和反引號。由單引號括起來的字元都作為普通字元出現。特殊字元用單引號括起來以後,也會失去原有意義,而只作為普通字元解釋。單引號用於保持引號內所有字元的字面值,即使引號內的 和回車也不例外,但是字串中不能出現單引號。注意是所有,只是單引號本身不能夠出現在其中 例...

Shell單引號,雙引號,反引號,反斜槓

shell單引號,雙引號,反引號,反斜槓 shell可以識別4種不同型別的引字符號 單引號字元 雙引號字元 反斜槓字元 反引號字元 1.單引號 grep susan phonebook susan goldberg 403 212 4921 susan topple 212 234 2343 如果我...