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.
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
I want:
cat /tmp/script
$HOSTNAME
Edit: 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:
See the section on “here documents” in the manual.