双引号
双引号保留除 "
终结符,$
扩展,`
命令替换和任何这些字符的\
转义(以及换行符)之外的所有字符。请注意,除非后跟特殊字符,否则将保留文字\
。
一般转义:
$ printf "\"quoted string\"\\n"
"quoted string"
$ printf "\`\`quoted string''\n"
``quoted string''
$ printf "four\\\\nthree\\\ntwo\\none\n"
four\nthree\ntwo
one
$ echo "var=\`echo \$var\`"
var=`echo $var`
$ echo "var=\$(echo \$var)"
var=$(echo $var)
可变扩展:
$ var=variable echo "$var \$var \\$var \\\$var"
variable $var \variable \$var
命令替换:
$ var=variable echo "var=`echo $var`"
var=variable
$ var=variable echo "var=$(echo $var)"
var=variable
删除换行符:
$ echo "multi\
> -line"
multi-line