heredoc - Writing a bash script from bash script. Lines without interpretation -
i want create bash script bash script. problem doing old echo style (example echo -e "some commands" > /path/to/file.sh) commands interpreted , substituted values.
googling found solution on forum: generating bash script bash script
there, use:
cat >/path/to/file.sh <<'eof' commands eof
if mini-script this, works... problem while try integrate in big script... basic "some commands"... generates error:
warning: here-document @ line xxxx delimited end-of-file (wanted `eof') ./myscript.sh: line xxxx: syntax error: unexpected end of file
what doing wrong? can't used inside functions or what's point of error... i'm not sure of being understanding error tries say. thank you.
the end delimiter here-document needs flush left, no indentation whatsoever, regardless of whether occurs in function or elsewhere.
indentation allowed, tabs, if here-document started <<-word
rather <<word
(any initial tabs removed start of each line of here-document).
also note if script outputting bash
script contains here-documents, delimiter of here-documents must different 1 used end contents of script.
since delimiter may arbitrary word, it's practice use descriptive delimiter, end_script
, or similar.
Comments
Post a Comment