【问题标题】:Shell use variable and escape dollar character at the same timeShell 同时使用变量和转义美元字符
【发布时间】:2014-04-02 19:42:13
【问题描述】:

如何在使用 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_

【问题讨论】:

    标签: shell eof cat dollar-sign


    【解决方案1】:

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

    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_
    

    【讨论】:

      猜你喜欢
      • 2016-10-19
      • 2011-07-06
      • 2021-04-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-28
      相关资源
      最近更新 更多