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


反引號位 (`) 位於鍵盤的Tab鍵的上方、1鍵的左方。注意與單引號(')位於Enter鍵的左方的區別。
  在Linux中起着命令替換的作用。命令替換是指shell能夠將一個命令的標准輸出插在一個命令行中任何位置。
  如下,shell會執行反引號中的date命令,把結果插入到echo命令顯示的內容中。
  [root@localhost sh]# echo The date is `date`
  The date is 2011年 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 tmp]# echo 'the date is `date`'
the date is `date`
[root@localhost tmp]# echo "the date is `date`"
the date is Fri Oct 9 00:11:56 CST 2015

[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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM