bash – 在cat命令中转义Unix中的美元符号

在Ubuntu上,我想得到一个磁盘文件:
foo $(bar)

我想使用cat命令创建此文件,例如

cat <<EOF > baz.txt
type_magic_incantation_here_that_will_produce_foo_$(bar)
EOF

问题是美元符号.我尝试了反斜杠,单引号和双引号字符的多种组合,但无法使其工作.

您可以在here文档中使用常规引用运算符:
$cat <<HERE
> foo \$(bar)
> HERE
foo $(bar)

或者您可以通过引用here-doc分隔符来禁用扩展:

$cat <<'HERE'  # note single quotes
> foo $(bar)
> HERE
foo $(bar)

相关文章

用的openwrt路由器,家里宽带申请了动态公网ip,为了方便把2...
#!/bin/bashcommand1&command2&wait从Shell脚本并行...
1.先查出MAMP下面集成的PHP版本cd/Applications/MAMP/bin/ph...
1、先输入locale-a,查看一下现在已安装的语言2、若不存在如...
BashPerlTclsyntaxdiff1.进制数表示Languagebinaryoctalhexa...
正常安装了k8s后,使用kubect工具后接的命令不能直接tab补全...