测试脚本如下:
- #!/bin/sh
- #filename: 3
- name=test
- echo $name
- echo "the name is $name"
- echo 'the name is $name'
通过: chmod a+x 3 把这个脚本设置为可执行的脚本,执行后得到的结果为:
test
the name is test
the name is $name
可以得知:在双引号中引用的是变量的值,单引号中则是单纯的字符串。
如果单引号在双引号里面,那么单引号作为普通字符。
如: echo "'$name'" ,显示的结果就是: 'test' .