Linux 中 反引號 單引號 雙引號的作用

    反引號位 (`) 位於鍵盤的Tab鍵的上方、1鍵的左方。注意與單引號(')位於Enter鍵的左方的區別。
  在Linux中起着命令替換的作用。命令替換是指shell能夠將一個命令的標準輸出插在一個命令行中任何位置。
  如下,shell會執行反引號中的date命令,把結果插入到echo命令顯示的內容中。
  [root@localhost fwz]# echo The date is `date`
  The date is 2016年 04月 21日 星期一 21:15:43 CST
  
  單引號、雙引號用於用戶把帶有空格的字符串賦值給變量事的分界符。
  [root@localhost fwz]# str="Today is Monday"
  [root@localhost fwz]# echo $str
  Today is Monday
  如果沒有單引號或雙引號,shell會把空格後的字符串解釋爲命令。
  [root@localhost fwz]# str=Today is Monday
  bash: is: command not found
  單引號和雙引號的區別。單引號告訴shell忽略所有特殊字符,而雙引號忽略大多數,但不包括$、\、`。
  [root@localhost fwz]# testvalue=100
  [root@localhost fwz]# echo 'The testvalue is $testvalue'
  The testvalue is $testvalue
  [root@localhost fwz]# echo "The testvalue is $testvalue"
  The testvalue is 100

也就表示單引號是強引用,雙引號是弱引用。
總結:反引號是命令替換、單引號是強引用、雙引號是弱引用。
發佈了34 篇原創文章 · 獲贊 92 · 訪問量 13萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章