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'