LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Environment Variables ( or something similar ) (https://www.linuxquestions.org/questions/linux-newbie-8/environment-variables-or-something-similar-610375/)

lumix 01-01-2008 12:13 PM

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.

Thanks.

p.s.
export does not do this.

Dinithion 01-01-2008 03:56 PM

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.

lumix 01-01-2008 06:28 PM

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.

AdaHacker 01-01-2008 07:00 PM

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.


All times are GMT -5. The time now is 06:28 AM.