How to pass an environment variable to an xterm session
Linux - SoftwareThis 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
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.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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?
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.
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
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.