Shell同时使用变量和转义美元字符

时间:2014-03-01 18:14:00

标签: shell eof cat dollar-sign

如何在shell脚本中使用变量并使用 cat<<同时转义美元字符? _ EOF _

重要的是我没有使用“或”字符。

这是我写的文字:

cat <<- _EOF_ >> "$serverconfigdir/$siteaddress"
    This is a sample text! Here is my variable below!
    $usethisvariable

    This is another sample text! $escapethisstring show it how it looks bla bla.
_EOF_

1 个答案:

答案 0 :(得分:2)

您需要在第二次出现时转义$

cat <<- _EOF_ >> "$serverconfigdir/$siteaddress"
    This is a sample text! Here is my variable below!
    $usethisvariable

    This is another sample text! \$escapethisstring show it how it looks bla bla.
_EOF_