title: How to check if stdin is from the terminal or a pipe in a shell script?
body: <p>I am writing a POSIX shell script that may or may not receive input from stdin as in <code>foo.sh &lt; test.txt</code>, non-interactively.</p>
  
  <p>How do I check whether there is anything on stdin, to avoid halting on <code>while read -r line...</code>?</p>