2

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

重要的是我没有使用 " 或 ' 字符。

这是我要写的文字:

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_
4

1 回答 1

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_
于 2014-03-01T18:17:41.473 回答