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.
I'm not clear on why we have to export variables in linux.
For example, in a programming language you define a variable and use it. In Windows, you define an environment variable and use it. In Linux you define a variable and then you have to export it. Where are we exporting it to?
Ok, I assume someone will say "outside the shell", but what does that mean? Is there a global variable area outside the shell where variables can be exchanged between shells? Is this the only place to which variables can be "exported"? Is this similar to private and public variables in programming?
Is there any way I can define WHICH other shells have access to my exported variables? Do all other applications running have access to my exported variables? What if another shell exports a variable with the same name but a different value, does it overwrite mine?
This adds the variable to the process environment. Under Bash (but not under the old Bourne shell) it is also possible
to declare a variable to be global on a single line by
export GLOBALVAR="global"
See also Man Page: export-1
I am not a programmer, so I have very little experience with variables. I hope this gets you the info you were seeking.
All processes have a process environment, containing environment variables.
In addition to that, shells have a local environment, containing local variables.
When you invoke an application, it inherits the process environment (containing the environment variables) from the shell, but not the local environment.
So if you are using a variable, and you want applications or commands that you execute to be able to see the variable as well, then you have to export it. Otherwise you don't.
It is important to note that if you start an application or command, it gets its own copy of the enivronment. Hence, you applications can never change any variables in your shell.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.