Prevent expressions enclosed in backticks from bei

2020-02-10 14:10发布

I have a text like this:

foo bar
`which which`

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

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

➜  ~  

How can I do this?

Edit

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?

With cat, I get

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

I don't want which which to be evaluated.

标签: bash shell
1条回答
2楼-- · 2020-02-10 14:46

Quote the label to prevent the backticks from being evaluated.

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

$ cat out
foo bar
`which which`
查看更多
登录 后发表回答