防止在反引号中包含的表达式在heredocs中求值 [英] Prevent expressions enclosed in backticks from being evaluated in heredocs

查看:82
本文介绍了防止在反引号中包含的表达式在heredocs中求值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的文字:

foo bar
`which which`

如果我使用heredoc进行此操作,则会得到一个空白文件:

If I do this using heredoc, I get a blank file:

➜  ~  echo <<EOT > out
heredoc> foo bar
heredoc> `which which`
heredoc> EOT
➜  ~  cat out

➜  ~  

我该怎么做?

哦,对不起,我打算做cat.问题是它将它写入文件:which: shell built-in command,即求值反引号.有没有做任何评估的方法吗?

Oh sorry, I meant to do cat. Problem is that it writes this to the file: which: shell built-in command, ie, evaluations backticks. Any way to do this without evaluating?

有了cat,我得到了

➜  ~  cat <<EOT > out
heredoc> foo bar
heredoc> `which which`
heredoc> EOT
➜  ~  cat out
foo bar
which: shell built-in command
➜  ~  

我不希望对which which进行评估.

推荐答案

引用标签以防止反引号得到评估.

Quote the label to prevent the backticks from being evaluated.

$ cat << "EOT" > out
foo bar
`which which`
EOT

$ cat out
foo bar
`which which`

这篇关于防止在反引号中包含的表达式在heredocs中求值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆