Search code examples
bashshelltty

Determining if the user is running a graphical interface at the present tty


Can a shell script determine whether the user is running a graphical interface at the same tty in which the user is working?

Maybe this isn't even possible?

EDIT:

I'm actually trying to write a shell script that displays a GUI (by using zenity/yad) when the user is running a window manager on the same tty as the user is working on. Otherwise, the script falls back to a plain command line interface.


Solution

  • Try to check the variable TERM or perhaps more precisely by checking the output of tset -q. The type of terminal would depend on it. In a normal console, it's just Linux while in most terminals it is xterm.

    Other things would be to check the variable $DISPLAY. Most of the time it's set when you're running on a GUI terminal.