how to have bash script check whether it's a x session?
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Distribution: Debian Etch (w/ dual-boot XP for gaming)
Hmm, whilst I don't have anything constructive to add to this, I don't have the XAUTHORITY envvar set, and running your commands (without the exit on the end) always tell me I'm not in X, even when I am.
At a guess, since everything's a file in Linux, presumably starting X will create a screen file somewhere (localhost:0), and you could check for that?
Edit: OK, I just searched for .*:0.* and got ~/.DCOPserver_$HOSTNAME_:0, but that's KDE-centric. Not so good, though it might form part of a test if it's quicker than the definitive method - assuming that the file is destroyed with X, which I haven't checked.
Another approach is processes - if X is running, you can see it with ps aux. However, that brings its own problems (why couldn't it have a longer and more unique name? ) - my output is
thanks for the replies. Indeed, $XAUTHORITY is not set on my system. I guess Andrzej way of using ps, grepping for X, is the one to go to do it properly.
[ ...However, I'll settle with Hobbletoe's version for the moment... ]
That value should always be set for an X session and never for a session not under X -- unless you manually set it in your login scripts (I have done this when I was routinely logging in and starting X programs I wanted to see on my local display).
Just one question... why are you doing this in ~/.profile and not ~/.xinitrc and ~/.xsession ?
Those are the two files which "traditionally" call programs which modify X.
Just put a line like:
xmodmap ~/.xmodmap &
somewhere above the last line in the file(s) -- and make sure you have the "&" because it is important -- and it should run just fine.
Of course, you're at liberty to do this however you want. I just didn't realize what you were doing at first; so, I answered the question without thinking about the actual problem you were trying to solve.
yes, you're right. However, for some weird reason, it's not executed if I put it in one of the ~/.x files. Actually, it seems these files are not executed on my system at all. But as it's a business machine which I don't administrate, at the end of the day, I don't really care as long as it works - which it does now, thanks again!