在cat命令中的Unix中跳过一个美元符号 [英] Escaping a dollar sign in Unix inside the cat command
本文介绍了在cat命令中的Unix中跳过一个美元符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Ubuntu上,我最终会得到一个磁盘文件:
On Ubuntu, I would like to end up with a disk file that reads:
foo $(bar)
我想使用 cat
命令,例如
cat <<EOF > baz.txt
type_magic_incantation_here_that_will_produce_foo_$(bar)
EOF
问题是美元符号。我尝试了多个反斜杠,单引号和双引号字符的组合,并且无法使其正常工作。
The problem is the dollar sign. I have tried multiple combinations of backslash, single-quote, and double-quote characters, and cannot get it to work.
推荐答案
您可以在这个文件中使用常规的引号运算符:
You can use regular quoting operators in a here document:
$ cat <<HERE
> foo \$(bar)
> HERE
foo $(bar)
或者您可以通过引用here-doc来禁用扩展分隔符:
or you can disable expansion by quoting the here-doc delimiter:
$ cat <<'HERE' # note single quotes
> foo $(bar)
> HERE
foo $(bar)
这篇关于在cat命令中的Unix中跳过一个美元符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文