LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (http://www.linuxquestions.org/questions/slackware-14/)
-   -   how to check in a bash script where the shell is run from (http://www.linuxquestions.org/questions/slackware-14/how-to-check-in-a-bash-script-where-the-shell-is-run-from-4175433655/)

nass 10-23-2012 05:35 AM

how to check in a bash script where the shell is run from
 
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

Quote:

setxkbmap -layout 'us,gr' -variant 'altgr-intl,extended' -option grp:alt_shift_toggle
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

crabboy 10-23-2012 08:56 AM

This works, but not sure in all cases:
Code:

# User specific aliases and functions

if [ x$WINDOWID != "x" ]; then
  echo "I'm in X!"
fi


bosth 10-23-2012 09:05 AM

You can add it to your ~/.xsession file. You could also test for DISPLAY being set in ~/.bashrc, but that will still run when you open a terminal session in X.

bnguyen 10-23-2012 09:08 AM

You have a login shell when connecting through putty , so you may want to check the variable $TERM -- in login and non-login shell, it is "linux" and "xterm" respectively.

crabboy 10-23-2012 09:23 AM

Quote:

Originally Posted by bnguyen (Post 4813059)
You have a login shell when connecting through putty , so you may want to check the variable $TERM -- in login and non-login shell, it is "linux" and "xterm" respectively.

The TERM variable is set to xterm when I telnet in with putty.

bnguyen 10-24-2012 12:35 AM

Quote:

Originally Posted by crabboy (Post 4813066)
The TERM variable is set to xterm when I telnet in with putty.

That's because in putty under Connection>Data there's an option called *Terminal-type string* which is set to "xterm" by default. So yes, it has to be changed to "linux" before connecting. Sorry, I did not check to be aware that putty has such option.


All times are GMT -5. The time now is 05:55 PM.