1. 程式人生 > >Linux Shell 中的反引號,單引號,…

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

    反引號位 (`) 位於鍵盤的Tab鍵的上方、1鍵的左方。注意與單引號(')位於Enter鍵的左方的區別。
  在Linux中起著命令替換的作用。命令替換是指shell能夠將一個命令的標準輸出插在一個命令列中任何位置。
  如下:

   shell會執行反引號中的date命令,把結果插入到echo命令顯示的內容中。
  [[email protected] sh]# echo The date is `date`
  The date is 2011年 03月 14日 星期一 21:15:43 CST
  
  單引號、雙引號用於使用者把帶有空格的字串賦值給變數時的分界符。
  [

[email protected] sh]# str="Today is Monday"
  [[email protected] sh]# echo $str
  Today is Monday
  如果沒有單引號或雙引號,shell會把空格後的字串解釋為命令。
  [[email protected] sh]# str=Today is Monday
  bash: is: command not found
  單引號和雙引號的區別。單引號告訴shell忽略所有特殊字元而雙引號忽略大多數,但不包括$、\、`
  [[email protected]
sh]# testvalue=100
  [[email protected] sh]# echo 'The testvalue is $testvalue'
  The testvalue is $testvalue
  [[email protected] sh]# echo "The testvalue is $testvalue"
  The testvalue is 100