Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
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.
Distribution: Hardy (Gnome on Ubuntu 8.04) on Compaq N600c laptop
Posts: 323
Rep:
Environment Variables ( or something similar )
Is there a way to set an env var from one shell in such a way that it is then also "set" (i.e. available, visible, usable, etc.) in another shell?
In other words:
1) open shell 1, (perhaps through gnome-terminal)
2) open shell 2, (same)
3) go to shell 1 and (somehow) set myvar="hello"
4) go to shell 2 and echo myvar
5) see "hello" echoed.
To achieve this, you will have to look at "something similar". You could make som API to do some sort of communication between shells, but it isn't possible to read variables from different shells. There is possibly some sort of communication API out there, somewhere. But as far as I know, there isn't anything build in.
Distribution: Hardy (Gnome on Ubuntu 8.04) on Compaq N600c laptop
Posts: 323
Original Poster
Rep:
Ah. Thanks.
Hmmm ...wait...can't this be done perhaps through pipes? There must be some well established way for processes in one shell to communicate with their neighbors in another.
There is no way to do this with environment variables as you describe. If the second shell were a child of the first, then using export would allow it to inherit the variable. However, in your scenario, the two shells are unrelated processes so that won't work.
As for communication between processes, yes, there are plenty of ways to do that. Maybe if you tell us what you're trying to accomplish, maybe someone can recommend an appropriate method.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.