Determining the type of terminal (classic Unix terminal vs graphical terminal)

bash

Solution

the `TERM` variable indicates the terminal type. when running in an x-terminal, it is usually `xterm` (but can also be `xterm-color-256` as Dmitry has hinted in his answer). the following code checks whether the value of $TERM starts with `xterm` (and thus catches several cases):

case "$TERM" in
   xterm*)
      echo "running as an x-terminal"
      ;;
   *)
      echo "not running as an x-terminal"
      ;;
esac

Problem

I'm configuring my prompt (`PS1`) via .bashrc and found one issue with my current configuration: I am using a 256 color scheme. This is not compatible with the classical terminal (accessible via e.g. Ctrl+Alt+F2) but looks beautiful in graphical terminals such as gnome-terminal, terminator, etc. So I have to change my prompt depending on the type of terminal. To do this, I need a condition for `if` clause to test the type of terminal. Do you know how to do this?

Original source