{"id":767,"date":"2025-09-24T14:41:25","date_gmt":"2025-09-24T06:41:25","guid":{"rendered":"https:\/\/play.datalude.com\/blog\/?p=767"},"modified":"2025-09-24T14:44:40","modified_gmt":"2025-09-24T06:44:40","slug":"heredoc-operators","status":"publish","type":"post","link":"https:\/\/play.datalude.com\/blog\/2025\/09\/heredoc-operators\/","title":{"rendered":"HEREDOC operators"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Basic usage<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>VARIABLE=\"variable\"\n\n# command format\ncat &lt;&lt; CONTENTS > \/path\/to\/output.conf\nNormal text here \nThe second line contains a $VARIABLE\n        These are Tabbed\n        Indented\nCONTENTS\n\n# Result, cat \/path\/to\/output.conf\nNormal text here\nThe second line contains a variable\n        These are Tabbed\n        Indented<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Output alternatives:<\/strong> Can also use >> to append to output file, or | tee to output to screen as it runs. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Quoting preserves content<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">If you're outputting a script you might need to preserve the variable notation instead of evaluating it. You can use either single or double quotes to do this. <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>VARIABLE=\"variable\"\n\n# command format\ncat &lt;&lt; 'CONTENTS' > \/path\/to\/output.conf\nNormal text here \nThe second line contains a $VARIABLE\n        These are Tabbed\n        Indented\nCONTENTS\n\n# Result, cat \/path\/to\/output.conf\nNormal text here \nThe second line contains a $VARIABLE\n        These are Tabbed\n        Indented\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Zapping Tabs<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The &lt;&lt;- construct will remove tabs from your input, which means you can format your code nicely. Doesn't work at the same time as \"CONTENTS\"<br><br><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>VARIABLE=\"variable\"\n\n# command format\ncat &lt;&lt;- CONTENTS > \/path\/to\/output.conf\nNormal text here \nThe second line contains a $VARIABLE\n\tThese are Tabbed\n\t\tIndented\nCONTENTS\n\n# Result, cat \/path\/to\/output.conf\nNormal text here \nThe second line contains a variable\nThese are Tabbed\nIndented\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Basic usage Output alternatives: Can also use >> to append to output file, or | tee to output to screen as it runs. Quoting preserves content If you're outputting a script you might need to preserve the variable notation instead of evaluating it. You can use either single or double quotes to do this. Zapping &#8230; <a title=\"HEREDOC operators\" class=\"read-more\" href=\"https:\/\/play.datalude.com\/blog\/2025\/09\/heredoc-operators\/\" aria-label=\"Read more about HEREDOC operators\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","footnotes":""},"categories":[144,4],"tags":[],"class_list":["post-767","post","type-post","status-publish","format-standard","hentry","category-bash-script","category-linux"],"_links":{"self":[{"href":"https:\/\/play.datalude.com\/blog\/wp-json\/wp\/v2\/posts\/767","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/play.datalude.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/play.datalude.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/play.datalude.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/play.datalude.com\/blog\/wp-json\/wp\/v2\/comments?post=767"}],"version-history":[{"count":3,"href":"https:\/\/play.datalude.com\/blog\/wp-json\/wp\/v2\/posts\/767\/revisions"}],"predecessor-version":[{"id":772,"href":"https:\/\/play.datalude.com\/blog\/wp-json\/wp\/v2\/posts\/767\/revisions\/772"}],"wp:attachment":[{"href":"https:\/\/play.datalude.com\/blog\/wp-json\/wp\/v2\/media?parent=767"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/play.datalude.com\/blog\/wp-json\/wp\/v2\/categories?post=767"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/play.datalude.com\/blog\/wp-json\/wp\/v2\/tags?post=767"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}