【问题标题】:How to interpret one variable but not another in a heredoc?如何在heredoc中解释一个变量而不解释另一个变量?
【发布时间】:2021-03-24 06:43:03
【问题描述】:

我想解释这个heredoc 的第一个变量,而不是其他两个变量。这可能吗?

cat << EOF >> "$__GREP_CACHE_FILE"

# (r) Recursively search pattern, (i) ignore case, (I) ignore binary files,
# (n) prefix with line number within file, (s) suppress error messages.
# Use path or current directory
function grepr() {
  # Usage: grepr PATTERN [PATH...]
  grep -rIins "$GREP_OPTIONS" '$1' '${2:-.}'
}
EOF

【问题讨论】:

    标签: bash heredoc


    【解决方案1】:

    根据@oguzismail 的评论,您可以避开其余的美元符号:

    cat << EOF >> "$__GREP_CACHE_FILE"
    
    # (r) Recursively search pattern, (i) ignore case, (I) ignore binary files,
    # (n) prefix with line number within file, (s) suppress error messages.
    # Use path or current directory
    function grepr() {
      # Usage: grepr PATTERN [PATH...]
      grep -rIins "\$GREP_OPTIONS" '\$1' '\${2:-.}'
    }
    EOF
    

    【讨论】:

      猜你喜欢
      • 2021-07-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多