{"id":1848,"date":"2014-02-12T08:37:06","date_gmt":"2014-02-12T08:37:06","guid":{"rendered":"http:\/\/blog.designed79.co.uk\/?p=1848"},"modified":"2014-02-12T08:37:06","modified_gmt":"2014-02-12T08:37:06","slug":"here-documents-indenting","status":"publish","type":"post","link":"https:\/\/blog.designed79.co.uk\/?p=1848","title":{"rendered":"HERE Documents &#8211; Indenting"},"content":{"rendered":"<p>The here-document is great, but it\u2019s messing up your shell script\u2019s formatting. You want to be able to indent for readability.<\/p>\n<p><strong>Solution<\/strong><\/p>\n<p>Use &lt;&lt;- and then you can use tab characters (only!) at the beginning of lines to indent this portion of your shell script.<\/p>\n<pre>     $ cat myscript.sh\r\n     ...<\/pre>\n<pre>          grep $1 &lt;&lt;-'EOF'\r\n             lots of data<\/pre>\n<pre>             can go here\r\n             it's indented with tabs\r\n             to match the script's indenting\r\n             but the leading tabs are\r\n             discarded when read\r\n             EOF<\/pre>\n<p><strong>Discussion<\/strong><\/p>\n<p>The hyphen just after the &lt;&lt; is enough to tell bash to ignore the leading tab charac- ters. This is for tab characters only and not arbitrary white space. This is especially important with the EOF or any other marker designation. If you have spaces there, it will not recognize the EOF as your ending marker, and the \u201chere\u201d data will continue through to the end of the file (swallowing the rest of your script). Therefore, you may want to always left-justify the EOF (or other marker) just to be safe, and let the for- matting go on this one line.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The here-document is great, but it\u2019s messing up your shell script\u2019s formatting. You want to be able to indent for readability. Solution [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1848","post","type-post","status-publish","format-standard","hentry","category-info-on-tech"],"_links":{"self":[{"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/1848","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1848"}],"version-history":[{"count":0,"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/1848\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1848"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1848"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1848"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}