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

You could simply try the X version first. If the X server fails to appear, exec returns with an error -- the only way exec can return. Then try the command-line version.
This is fundamentally what I had thought of doing myself, even though, really I was rather thinking of putting some minimal Tk code in an eval block instead. Yes: I know that basically that would mean doing the same thing twice, but it seems somewhat cleaner... of course unless there's an even cleaner solution.