开发者

BASH script to pass variables without substitution into new script

As part of a system build script I have a script that creates various files and configurations.

However one part of the build script creates a new script that contains variables that I don't want resolved when the build script runs. Code snippet example

cat - > /etc/profile.d/mymotd.sh <<EOF
hostname=`uname -n`
echo -e "Hostname is $hostname"
EOF

I have tried all sorts of combinations of ' and " and ( and [ but I c开发者_开发问答annot get the script to send the content without substituting the values and placing the substitutes in the new script rather than the original text.

Ideas?


The easiest method, assuming you don't want anything to be substituted in the here doc, is to put the EOF marker in quotes, like this:

cat - > /etc/profile.d/mymotd.sh <<'EOF'
hostname=`uname -n`
echo -e "Hostname is $hostname"
EOF


Easiest is to escape the $

echo -e "Hostname is \$hostname"

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜