in reply to Re: How to detect X?
in thread How to detect X?

If an X server is available, it can be reached/detected via the %ENV hash:
if ($ENV{DISPLAY}) { print "Found X server at $ENV{DISPLAY}\n"; };
Yes, I knew, but a random look at the pages I found with google seemed to suggest that this may be highly unreliable, in particular that it may remain set also where not available. I have quickly checked here on a few machines and I have the impression that it is indeed so.
Keep in mind that it might be practical if the UI-less variant can be used even when there is an X server available; examples are shell-scripts and pipes...
Indeed this is why I wrote
I would like to write a script that supports both a cmd line UI and a GUI (Tk), and in addition to cmd-line switches to activate one or the other[...]
In the first place.