本文介绍了从国际preting prevent的bash没有引述的一切的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要输出一些文本bash脚本,但在一个脚本。我用的猫,但它有一个缺点。它的间$ P $其中pts变量和东西期间,它被写入。我想的 prevent这个

I need to output some text as bash script, but in a script. I use cat for this, but it has one drawback. It interprets variables and stuff during it is being written. I do want to prevent this.

如何做到这一点的没有引用的所有可变因素(我的剧本是failrly长​​)?示例

How to do that without quoting all varibles (my script is failrly long)? Example

cat >/tmp/script << EOF
  $HOSTNAME
  # lots of other stuff I do NOT want to escape like \$VARIABLE
  # ...
EOF

cat /tmp/script
myhostname.mylan

我想:

cat /tmp/script
$HOSTNAME

编辑:请注意我的脚本(这里只的 $ HOSTNAME 的)很长,我不想改变这一切。此外报价单不起作用以&lt;&LT;

Please note my script (here only $HOSTNAME) is very long, I dont want to change it all. Also single quoting does not work with <<

cat >/tmp/script '<< EOF
  $HOSTNAME
EOF'
File not found: EOF'

有什么诀窍?谢谢你。

What's the trick? Thanks.

推荐答案

如果你想要的一切报价:

If you want everything quoted:

cat << 'EOF'
stuff here with $signs is OK
as are `backquotes`
EOF

参见手册中的文件在这里的部分。

See the section on "here documents" in the manual.

这篇关于从国际preting prevent的bash没有引述的一切的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 16:57