title: check isatty in bash
body: <p>I want my shell to detect if human behavior, then show the prompt.</p>
  
  <p>So, assume the file name is test.bash</p>
  
  <pre><code>#!/bin/bash
  if [ "x" != "${PS1:-x}" ] ;then
   read -p "remove test.log Yes/No" x
   [ "$x" = "n" ] &amp;&amp; exit 1
  fi
  rm -f test.log
  </code></pre>
  
  <p>But, I found it can not work if I haven't set PS1.  Is there better method?</p>
  
  <p>my test methods:</p>
  
  <pre><code>./test.bash                  # human interactive
  ./test.bash &gt; /tmp/test.log  # stdout in batch mode
  ls | ./test.bash             # stdin in batch mode
  </code></pre>