I want to create a bash script from a bash script. The problem doing it with old echo style (example echo -e "some commands" > /path/to/file.sh) is the commands are interpreted and substituted by its values.
Googling I found this solution on this forum:
Generating a bash script from a bash script
There, they use:
cat >/path/to/file.sh <<'EOF'
The end delimiter for a here-document needs to be flush to the left, with no indentation whatsoever, regardless of whether it occurs in a function or elsewhere.
Indentation is allowed, but only with tabs, if the here-document is started with
<<-word rather than with
<<word (any initial tabs will then be removed from the start of each line of the here-document).
Also note that if the script that you are outputting with your
bash script contains here-documents, then the delimiter of those here-documents must be different from the one used to end the contents of the script.
Since the delimiter may be an arbitrary word, it's good practice to use a descriptive delimiter, like
END_SCRIPT, or similar.