Lucas Lacir Lucas Lacir - 1 year ago 88
Linux Question

How create a bash script with another bash script?

I'm creating a bash script that will run only once, but after that, it'll create another bash script. I've tried to use CAT EOT, but the problem is that, instead of copy/paste the text inside the new bash, it "executes" all variables inside.

E.g.: instead of write "

date=$(date +%d)
", it is writing "
" in the new archive.

How can I make it copy/paste, instead of execute the command?

Answer Source

To prevent variables from being expanded in a here-doc, put quotes around the token.

cat <<'EOT'
This is a here-doc
that contains $variable
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download