title: Detecting interactive shell within ksh ENV script
body: <p>What's the preferred way to determine if a given ksh invocation is running an interactive shell?</p>
  
  <p>I have some commands in an <code>ENV</code> file that I would like to skip for non-interactive ksh invocations (e.g. when executing a shell script).</p>
  
  <p>I've seen suggesting ranging <a href="http://sage.org/lists/sage-members-archive/1999/msg00551.html" rel="nofollow noreferrer">from</a>:</p>
  
  <pre><code>if [[ $- = *i* ]]; then
      # do interactive stuff
  fi
  </code></pre>
  
  <p>...to not even sourcing <code>.kshrc</code> unless the shell is determined to be interactive using this cryptic <a href="http://sage.org/lists/sage-members-archive/1999/msg00552.html" rel="nofollow noreferrer">incantation</a>:</p>
  
  <pre><code>ENVIRON=$HOME/.kshrc                                    export ENVIRON
  ENV='${ENVIRON[(_$-=1)+(_=0)-(_$-!=_${-%%*i*})]}'       export ENV
  </code></pre>