title: How can a shell script tell if it is running in an xterm window with 256-color support?
body: <p>I'm writing a shell script that I would like to use 256-color support when present.
  In a just world, <code>xterm</code> would simply set the <code>TERM</code> environment variable to <code>xterm-256color</code> and I'd use <code>tput colors</code> to discover the support.  </p>
  
  <p>But we live in an unjust world.  <code>xterm</code> sets <code>TERM</code> to <code>xterm</code> even when launched with <code>TERM=xterm-256color</code>.  Is there anything I can do from within a shell script to discover whether the script is running with stdout connected to a tty running in a 256-color <code>xterm</code> window?  If so, I can set the environment variable myself.</p>