LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices

Reply
 
LinkBack Search this Thread
Old 10-23-2012, 05:35 AM   #1
nass
Member
 
Registered: Apr 2006
Location: Athens, Greece
Distribution: slack(64|32)_v(13.37|14.0), debian6, ubuntu
Posts: 629

Rep: Reputation: 36
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
 
Old 10-23-2012, 08:56 AM   #2
crabboy
Moderator
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,822

Rep: Reputation: 120Reputation: 120
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
 
Old 10-23-2012, 09:05 AM   #3
bosth
Member
 
Registered: Apr 2011
Posts: 217

Rep: Reputation: 60
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.
 
Old 10-23-2012, 09:08 AM   #4
bnguyen
Member
 
Registered: Jul 2010
Distribution: Slackware
Posts: 125

Rep: Reputation: 32
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.
 
Old 10-23-2012, 09:23 AM   #5
crabboy
Moderator
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,822

Rep: Reputation: 120Reputation: 120
Quote:
Originally Posted by bnguyen View Post
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.
 
Old 10-24-2012, 12:35 AM   #6
bnguyen
Member
 
Registered: Jul 2010
Distribution: Slackware
Posts: 125

Rep: Reputation: 32
Quote:
Originally Posted by crabboy View Post
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.
 
  


Reply

Tags
bash, environment variable, xsession


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash Shell Script - Check SQL file for corruption RML1992 Linux - General 3 09-14-2012 12:47 AM
[SOLVED] Bash Shell Script to check if a string has only alphabets and digits. aswani Programming 8 08-16-2012 09:49 AM
how to check folder if it has files in it using Bash Shell script vincent.dang Linux - Newbie 7 08-05-2010 07:58 PM
in bash shell how to run shell script during startup rammohan04 Red Hat 2 07-31-2009 02:07 AM
Check if actions in bash shell script are performed well proNick Linux - Newbie 6 02-09-2009 07:25 PM


All times are GMT -5. The time now is 04:39 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration