雙引號
雙引號保留除 "
終結符,$
擴充套件,`
命令替換和任何這些字元的\
轉義(以及換行符)之外的所有字元。請注意,除非後跟特殊字元,否則將保留文字\
。
一般轉義:
$ 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