shell里面的引用
"" 雙引號 引用除了$(美元符號), `(反引號) \(反斜線)之外的所有字符
'' 單引號 引用所有的字符
`` 反引號 shell將反引號的內容解釋為系統命令
\ 反斜線 轉義符,屏蔽一個字符的特殊意義
"$variable",利用雙引號引用變量可以防止字符串分隔,
保留變量中的空格
vi double.sh
#!/bin/bash
variable1=2010
echo "$variable1"
echo $variable1
variable2="x y z" #字符之間用多個空格分開
echo "$variable2"
echo $variable2
執行程序: ./double.sh
執行結果:
2010
2010
x y z
x y z
雙引號可以解析變量的值,單引號則原樣輸出
echo "$PWD is the current directory"
/home/daheng/test_program is the current directory
echo '$PWD is the current directory'
$PWD is the current directory
vi stephane.sh #單引號分為三段輸出
#!/bin/bash
echo "why can't I write 's between single quotes"
echo 'Why can'"'"'t I write' "'"'s between single quotes'