title: Bash add newline if missing
body: <p>I have difficulties in understanding the following code:</p>
  
  <pre><code>    lastline=$(tail -n 1 $bc; echo x); lastline=${lastline%x}
      if [ "${lastline: -1}" != $'\n' ]; then
          echo &gt;&gt; $bc
      fi
  </code></pre>
  
  <p>I suppose it's all about adding a <code>\n</code> in the file <code>$bc</code> if the last line is not already one. However <code>echo x</code> and <code>lastline%x</code> and <code>${lastline: -1}</code> does not make sense to me at all. What am I missing?</p>
  
  <p>The file <code>$bc</code> contains only lines like:</p>
  
  <pre><code>Sample1,ATAGFAT
  </code></pre>