LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 05-18-2009, 01:09 PM   #1
Leo Simon
LQ Newbie
 
Registered: Aug 2004
Posts: 22

Rep: Reputation: 0
How to pass an environment variable to an xterm session


Hi

I have multiple xterm sessions open at once. They have different numbers of columns. I want my editor (vi) to be able to distinguish between sessions with many and sessions with few columns. If I could set an environment variable when I open an xterm session, all would be fine, but am unable to do this. The following *should* work I believe,
"xterm -e "setenv LINELENGTH=178", but whenever I use the -e flag, the xterm session flashes on then off. Another alternative that would work is if I could read the Identify table that I can get from left-clicking at the top left corner of the session screen. Then I could parse the Geometry field. But I'm unable to call up the that table from within a shell.

Any help would be most appreciated!

Leo
 
Old 05-18-2009, 01:26 PM   #2
norobro
Member
 
Registered: Feb 2006
Distribution: Debian Sid
Posts: 792

Rep: Reputation: 331Reputation: 331Reputation: 331Reputation: 331
Don't know whether this will help or not, but try "-hold"
 
Old 05-18-2009, 01:40 PM   #3
Leo Simon
LQ Newbie
 
Registered: Aug 2004
Posts: 22

Original Poster
Rep: Reputation: 0
Thanks norobro.

Trouble with the -hold flag is that it prevents me from using the terminal session interactively. For example, xterm -hold -e ls
opens an xterm window, lists files but doesn't return me to a command prompt. Any suggestions as to how to get this to happen?
 
Old 05-18-2009, 02:46 PM   #4
norobro
Member
 
Registered: Feb 2006
Distribution: Debian Sid
Posts: 792

Rep: Reputation: 331Reputation: 331Reputation: 331Reputation: 331
How about:
Code:
xterm -e "export LINELENGTH=178;bash"
 
Old 05-18-2009, 03:05 PM   #5
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,083

Rep: Reputation: 405Reputation: 405Reputation: 405Reputation: 405Reputation: 405
Quote:
Originally Posted by Leo Simon View Post
Hi

I have multiple xterm sessions open at once. They have different numbers of columns. I want my editor (vi) to be able to distinguish between sessions with many and sessions with few columns. If I could set an environment variable when I open an xterm session, all would be fine, but am unable to do this. The following *should* work I believe,
"xterm -e "setenv LINELENGTH=178", but whenever I use the -e flag, the xterm session flashes on then off. Another alternative that would work is if I could read the Identify table that I can get from left-clicking at the top left corner of the session screen. Then I could parse the Geometry field. But I'm unable to call up the that table from within a shell.

Any help would be most appreciated!

Leo
That's to be expected. You are not opening a shell so it just runs that command and exits.

You need to run bash (or you could run vim or whatever directly if that's all you need, that way you don't waste memory on something you won't be using anyway).

So the suggestion above should work, but there's no need really to be that cryptic, just exporting the variable on the current shell will work the same.

Code:
$ export foo=bar
$ urxvtc #or xterm or whatever
#in the new term
$ echo $foo
bar
When a variable is marked for exportation, it's copied into the environment of all the new subshells that are opened from that one where you exported the variable.

PS: it really can be even simpler:

Code:
foo=bar xterm

Last edited by i92guboj; 05-18-2009 at 03:14 PM.
 
Old 05-18-2009, 05:32 PM   #6
Leo Simon
LQ Newbie
 
Registered: Aug 2004
Posts: 22

Original Poster
Rep: Reputation: 0
Thanks again to norobro and to i92guboj for your reply.

norobro's second reply worked perfectly. I'm doing nonstandard things, i.e., using fvwm to manage my windows and the tcsh shell. So for the record, I did the following:

- in my fvwm startup script, I open all of my terminals using
Code:
xterm ... -e "setenv TEXTWIDTH $TEXTWIDTH; tcsh"
then my macro to call vi says something like
Code:
vi -c":set textwidth=$TEXTWIDTH"
and all works beautifully.
 
Old 05-18-2009, 05:49 PM   #7
norobro
Member
 
Registered: Feb 2006
Distribution: Debian Sid
Posts: 792

Rep: Reputation: 331Reputation: 331Reputation: 331Reputation: 331
You're welcome. I had to experiment a bit to get it to work. Anyway I'm glad that you got it working
 
  


Reply



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



Similar Threads
Thread Thread Starter Forum Replies Last Post
pass alias to xterm sharky Programming 9 02-23-2009 01:21 PM
pass the variable contain lrios Programming 7 04-18-2008 04:56 PM
Set Environment Variable within VNC Session? arew264 Linux - Software 0 01-06-2008 04:47 PM
Changing environment variable for gnome session from gnome-terminal pymehta Linux - Software 1 10-11-2005 05:19 PM
Pass text to variable Zed Linux - Software 6 05-12-2003 03:02 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 11:53 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration