Shell – How to the script know when I’m in a virtual console vs. an xterm

command lineshellterminalxterm

A few of my scripts (keymap changing, public key adding) need to act differently when in a virtual console vs. in an xterm. What's the real code for

#!/bin/ksh
if [[ in_a_virtual_console ]]; then
...
else
...
fi

Best Answer

It sounds to me like you want to check whether or not there is a X server to connect to.

Something like:

if [ -n "$DISPLAY" ]; then
  : X
else
  : no X
fi
Related Question