title: Bash/Python: does `echo` command insert a newline when acting as input to another command?
body: <p>I have a simple python script <code>line_printer.py</code>:</p>
  
  <pre><code>import fileinput
  i = 1
  for line in fileinput.input():
      print 'Line', str(i), ':', line.strip()
      i+=1
  </code></pre>
  
  <p>I'm trying to understand how piping data in from the <code>echo</code> command to this script affects the result versus reading the data in from file.</p>
  
  <p>Consider the following call and output:</p>
  
  <pre><code>$ echo -e "chicken\ncow\npig"
  chicken
  cow
  pig
  $
  </code></pre>
  
  <p>This to me looks like <code>echo</code> has appended an invisble <code>\n</code> after the "g" in pig.  So, how come when I call:</p>
  
  <pre><code>echo -e "chicken\ncow\npig" | python line_printer.py
  </code></pre>
  
  <p>I get:</p>
  
  <pre><code>Line 1 : chicken
  Line 2 : dog
  Line 3 : cow
  </code></pre>
  
  <p>as the output and not:</p>
  
  <pre><code>Line 1 : chicken
  Line 2 : dog
  Line 3 : cow
  Line 4 : 
  </code></pre>
  
  <p>At first I thought the behaviour of Python's <code>fileinput</code> module might be to discard the final line in a file if it is blank.  But when I try using the contents of a file <code>some_lines.txt</code>:</p>
  
  <pre><code>chicken
  dog
  cow
  &lt;blank line&gt;
  </code></pre>
  
  <p>as the input:</p>
  
  <pre><code>python line_printer.py some_lines.txt
  </code></pre>
  
  <p>The output I get is:</p>
  
  <pre><code>Line 1 : chicken
  Line 2 : dog
  Line 3 : cow
  Line 4 : 
  </code></pre>
  
  <p>So why does <code>line_printer.py</code> give different results on the input depending on whether it originated from stdin versus originated from a file?  Best I can tell, both stdin (from <code>echo</code>) and the file (from <code>some_lines.txt</code>) finish with a <code>\n</code>, so I would either expect the output of both to include the <code>Line 4 :</code> or the output of neither to include it.</p>