title: Trailing new line after piping to a command: is there any standard?
body: <p>Answering <a href="https://stackoverflow.com/q/36621909/1983854">How to remove the last CR char with <code>cut</code></a> I found out that some programs do add a trailing new line to the end of a string, while others don't:</p>
  
  <p>Say we have the string <code>foobar</code> and print it with <code>printf</code> so that we don't get an extra new line:</p>
  
  <pre><code>$ printf "foobar" | od -c
  0000000   f   o   o   b   a   r
  0000006
  </code></pre>
  
  <p>Or with <code>echo -n</code>:</p>
  
  <pre><code>$ echo -n "foobar" | od -c
  0000000   f   o   o   b   a   r
  0000006
  </code></pre>
  
  <p>(<code>echo</code>'s default behaviour is to return the output followed by a newline, so <code>echo "foobar"</code> returns <code>f   o   o   b   a   r  \n</code>).</p>
  
  <p>Neither <code>sed</code> nor <code>cat</code> do add any extra character:</p>
  
  <pre><code>$ printf "foobar" | sed 's/./&amp;/g' | od -c
  0000000   f   o   o   b   a   r
  0000006
  $ printf "foobar" | cat - | od -c
  0000000   f   o   o   b   a   r
  0000006
  </code></pre>
  
  <p>Whereas both <code>awk</code> and <code>cut</code> do. Also <code>xargs</code> and <code>paste</code> add this trailing new line:</p>
  
  <pre><code>$ printf "foobar" | cut -b1- | od -c
  0000000   f   o   o   b   a   r  \n
  0000007
  $ printf "foobar" | awk '1' | od -c
  0000000   f   o   o   b   a   r  \n
  0000007
  $ printf "foobar" | xargs | od -c
  0000000   f   o   o   b   a   r  \n
  0000007
  $ printf "foobar" | paste | od -c
  0000000   f   o   o   b   a   r  \n
  0000007
  </code></pre>
  
  <p>So I was wondering: why is this different behaviour? Is there anything POSIX suggests about this?</p>
  
  <p>Note I am running all of this in my Bash 4.3.11 and the rest is:</p>
  
  <ul>
  <li>GNU Awk 4.0.1</li>
  <li>sed (GNU sed) 4.2.2</li>
  <li>cat (GNU coreutils) 8.21</li>
  <li>cut (GNU coreutils) 8.21</li>
  <li>xargs (GNU findutils) 4.4.2</li>
  <li>paste (GNU coreutils) 8.21</li>
  </ul>