<feed
    xmlns="http://www.w3.org/2005/Atom"
    xmlns:content="http://purl.org/rss/1.0/modules/content/"
    xml:lang="en">
  <link rel="self"      type="application/atom+xml" href="https://euandre.org/en/til/feed.sh.xml" />
  <link rel="alternate" type="text/html"            href="https://euandre.org/en/til/" hreflang="en" />
  <title>EuAndreh&apos;s website</title>
  <subtitle>TIL</subtitle>
  <id>https://euandre.org/en/til/feed.sh.xml</id>
  <updated>2026-09-05T20:22:11+00:00</updated>
  <author>
    <name>EuAndreh</name>
    <email>eu@euandre.org</email>
  </author>
  <entry xml:lang="en">
    <title type="html">
      Multiline comments in POSIX sh
    </title>
    <link type="text/html" rel="alternative" href="https://euandre.org/en/til/2026/09/05/multiline-sh-comments.html" title="Multiline comments in POSIX sh" />
    <published>
      2026-09-05T00:00:00+00:00
    </published>
    <id>
      https://euandre.org/en/til/2026/09/05/multiline-sh-comments.html
    </id>
    <author>
      <name>
        EuAndreh
      </name>
      <email>
        eu@euandre.org
      </email>
    </author>
    <summary type="html">
        &lt;div class=&quot;paragraph&quot;&gt;
          &lt;p&gt;I realized one can use heredocs for multiline comments in sh:&lt;/p&gt;
        &lt;/div&gt;
        &lt;div class=&quot;listingblock&quot;&gt;
          &lt;div class=&quot;content&quot;&gt;
    </summary>
    <content type="html" xml:base="en/til/2026/09/05/multiline-sh-comments.html">
        &lt;div class=&quot;paragraph&quot;&gt;
          &lt;p&gt;I realized one can use heredocs for multiline comments in sh:&lt;/p&gt;
        &lt;/div&gt;
        &lt;div class=&quot;listingblock&quot;&gt;
          &lt;div class=&quot;content&quot;&gt;
            &lt;table&gt;
              &lt;tbody&gt;
                &lt;tr&gt;
                  &lt;td&gt;
                    &lt;pre class=&quot;lineno&quot;&gt;&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L1&quot;
     href=&quot;#B1-L1&quot;&gt;1&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L2&quot;
     href=&quot;#B1-L2&quot;&gt;2&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L3&quot;
     href=&quot;#B1-L3&quot;&gt;3&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L4&quot;
     href=&quot;#B1-L4&quot;&gt;4&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L5&quot;
     href=&quot;#B1-L5&quot;&gt;5&lt;/a&gt;&lt;/pre&gt;
                  &lt;/td&gt;
                  &lt;td&gt;
                    &lt;pre&gt;cat &amp;lt;&amp;lt;&apos;COMMENT&apos; &amp;gt; /dev/null
if wip; then
        unfinished and broken syntax &amp;gt;
fii
COMMENT&lt;/pre&gt;
                  &lt;/td&gt;
                &lt;/tr&gt;
              &lt;/tbody&gt;
            &lt;/table&gt;
          &lt;/div&gt;
        &lt;/div&gt;
        &lt;div class=&quot;paragraph plaintext&quot;&gt;
          &lt;p&gt;&lt;a href=&quot;multiline-sh-comments.html.0.txt&quot;&gt;plaintext&lt;/a&gt;&lt;/p&gt;
        &lt;/div&gt;
        &lt;div class=&quot;paragraph&quot;&gt;
          &lt;p&gt;…​instead of:&lt;/p&gt;
        &lt;/div&gt;
        &lt;div class=&quot;listingblock&quot;&gt;
          &lt;div class=&quot;content&quot;&gt;
            &lt;table&gt;
              &lt;tbody&gt;
                &lt;tr&gt;
                  &lt;td&gt;
                    &lt;pre class=&quot;lineno&quot;&gt;&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B2-L1&quot;
     href=&quot;#B2-L1&quot;&gt;1&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B2-L2&quot;
     href=&quot;#B2-L2&quot;&gt;2&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B2-L3&quot;
     href=&quot;#B2-L3&quot;&gt;3&lt;/a&gt;&lt;/pre&gt;
                  &lt;/td&gt;
                  &lt;td&gt;
                    &lt;pre&gt;# if wip; then
#       unfinished and broken syntax &amp;gt;
# fii&lt;/pre&gt;
                  &lt;/td&gt;
                &lt;/tr&gt;
              &lt;/tbody&gt;
            &lt;/table&gt;
          &lt;/div&gt;
        &lt;/div&gt;
        &lt;div class=&quot;paragraph plaintext&quot;&gt;
          &lt;p&gt;&lt;a href=&quot;multiline-sh-comments.html.1.txt&quot;&gt;plaintext&lt;/a&gt;&lt;/p&gt;
        &lt;/div&gt;
        &lt;div class=&quot;paragraph&quot;&gt;
          &lt;p&gt;What is going on: the &lt;a href=
          &quot;https://pubs.opengroup.org/onlinepubs/9799919799/utilities/V3_chap02.html#tag_19_07_04&quot;&gt;language defines&lt;/a&gt;
          &lt;code&gt;&amp;lt;&amp;lt;&lt;/code&gt; as a redirect of the &quot;here-document&quot; type. After &lt;code&gt;&amp;lt;&amp;lt;&lt;/code&gt; you can put
          anything, and sh will use that as a token to look for on the following lines:&lt;/p&gt;
        &lt;/div&gt;
        &lt;div class=&quot;listingblock&quot;&gt;
          &lt;div class=&quot;content&quot;&gt;
            &lt;table&gt;
              &lt;tbody&gt;
                &lt;tr&gt;
                  &lt;td&gt;
                    &lt;pre class=&quot;lineno&quot;&gt;&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B3-L1&quot;
     href=&quot;#B3-L1&quot;&gt;1&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B3-L2&quot;
     href=&quot;#B3-L2&quot;&gt;2&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B3-L3&quot;
     href=&quot;#B3-L3&quot;&gt;3&lt;/a&gt;&lt;/pre&gt;
                  &lt;/td&gt;
                  &lt;td&gt;
                    &lt;pre&gt;cat &amp;lt;&amp;lt;&apos;bleh&apos;
...
bleh&lt;/pre&gt;
                  &lt;/td&gt;
                &lt;/tr&gt;
              &lt;/tbody&gt;
            &lt;/table&gt;
          &lt;/div&gt;
        &lt;/div&gt;
        &lt;div class=&quot;paragraph plaintext&quot;&gt;
          &lt;p&gt;&lt;a href=&quot;multiline-sh-comments.html.2.txt&quot;&gt;plaintext&lt;/a&gt;&lt;/p&gt;
        &lt;/div&gt;
        &lt;div class=&quot;paragraph&quot;&gt;
          &lt;p&gt;Make sure to include the &lt;code&gt;&apos;quotes&apos;&lt;/code&gt; around the word, otherwise anything with a &lt;code&gt;$&lt;/code&gt;
          would get replaced just like a &lt;code&gt;&quot;double-quoted&quot;&lt;/code&gt; string.&lt;/p&gt;
        &lt;/div&gt;
        &lt;div class=&quot;paragraph&quot;&gt;
          &lt;p&gt;&quot;bleh&quot; works fine, like any word would.&lt;/p&gt;
        &lt;/div&gt;
        &lt;div class=&quot;paragraph&quot;&gt;
          &lt;p&gt;But that example left as-is would print the string to stdout. To avoid that, we shove the contents to
          &lt;code&gt;/dev/null&lt;/code&gt;. So it isn’t technically a comment, its more like a constant string that gets emitted
          and discarded.&lt;/p&gt;
        &lt;/div&gt;
        &lt;div class=&quot;paragraph&quot;&gt;
          &lt;p&gt;Sure its hacky, but at this point what in sh isn’t? It even supports nesting!&lt;/p&gt;
        &lt;/div&gt;
        &lt;div class=&quot;listingblock&quot;&gt;
          &lt;div class=&quot;content&quot;&gt;
            &lt;table&gt;
              &lt;tbody&gt;
                &lt;tr&gt;
                  &lt;td&gt;
                    &lt;pre class=&quot;lineno&quot;&gt;&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B4-L1&quot;
     href=&quot;#B4-L1&quot;&gt;1&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B4-L2&quot;
     href=&quot;#B4-L2&quot;&gt;2&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B4-L3&quot;
     href=&quot;#B4-L3&quot;&gt;3&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B4-L4&quot;
     href=&quot;#B4-L4&quot;&gt;4&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B4-L5&quot;
     href=&quot;#B4-L5&quot;&gt;5&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B4-L6&quot;
     href=&quot;#B4-L6&quot;&gt;6&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B4-L7&quot;
     href=&quot;#B4-L7&quot;&gt;7&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B4-L8&quot;
     href=&quot;#B4-L8&quot;&gt;8&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B4-L9&quot;
     href=&quot;#B4-L9&quot;&gt;9&lt;/a&gt;&lt;/pre&gt;
                  &lt;/td&gt;
                  &lt;td&gt;
                    &lt;pre&gt;cat &amp;lt;&amp;lt;&apos;COMMENT1&apos; &amp;gt; /dev/null

cat &amp;lt;&amp;lt;&apos;COMMENT&apos; &amp;gt; /dev/null

# ... code ...

COMMENT

COMMENT1&lt;/pre&gt;
                  &lt;/td&gt;
                &lt;/tr&gt;
              &lt;/tbody&gt;
            &lt;/table&gt;
          &lt;/div&gt;
        &lt;/div&gt;
        &lt;div class=&quot;paragraph plaintext&quot;&gt;
          &lt;p&gt;&lt;a href=&quot;multiline-sh-comments.html.3.txt&quot;&gt;plaintext&lt;/a&gt;&lt;/p&gt;
        &lt;/div&gt;
        &lt;div class=&quot;paragraph&quot;&gt;
          &lt;p&gt;I’ve never committed any code with this, just used while debugging sh code. Make sure to handle with
          care&lt;/p&gt;
        &lt;/div&gt;
    </content>
  </entry>
</feed>
