hello everyone, I am fuzzy about how to set a command in a script to be run only when the shell is running within an X session. basically, in ~/.bashrc I set my keyboard maps as
If I am connecting through putty , or otherwise, and i just open a command prompt window, I DONT want this command to run. If on the other hand, i have an X session running (locally or remotely) I want this command to run. how can I do this checking in a bash script? Is there a bash environment variable I can be looking at? some other way? Thank you for your help asked 22 Oct '12, 19:05 synthnassizer |
While ranton's answer is generic and adequate, for the specific case of setxkbmap (which is required to be run only during Xsessions) a more appropriate place holder for the above command is in the window managers xinitrc file. this should be ~/.xinitrc but different wm's place it elsewhere. fluxbox has it in ~/.fluxbox/startup vnc sessions have it ~/.vnc/xstartup The above is not complete, but they give you an idea of where to look for these files. answered 07 Dec '12, 05:32 synthnassizer |
Check the DISPLAY variable. If it's set, you're in an X session:
answered 02 Mar '13, 20:30 cfajohnson |
Well, normally I would say check the TERM environment variable, but Putty configurations often set this to xterm just like an actual xterm so that's not much help. However, depending on your exact needs you can make PUTTY set an environment variable of your own choosing which you can check for by setting it in your Putty session configuration under Connection --> Data. answered 31 Oct '12, 14:36 ranton |