Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This 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!


  Search this Thread
Old 05-27-2005, 07:53 AM   #1
Registered: Mar 2005
Location: berlin
Distribution: Redhat 9, Fedora 3
Posts: 70

Rep: Reputation: 15
why do we have to export variables?

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 is all a bit foggy.

Old 05-27-2005, 08:24 AM   #2
Senior Member
Registered: Mar 2005
Location: Kentucky
Distribution: Slackware64-current
Posts: 1,837

Rep: Reputation: 452Reputation: 452Reputation: 452Reputation: 452Reputation: 452

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.
Old 05-27-2005, 09:27 AM   #3
Registered: Sep 2004
Distribution: Debian, Ubuntu, BeatrIX, OpenWRT
Posts: 273

Rep: Reputation: 30
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.




Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
export variables alaios Linux - General 3 12-04-2004 08:33 AM
keep my export variables captain-cat Linux - Newbie 9 06-23-2004 06:22 AM
export variables radnix Linux - General 2 04-28-2004 07:52 PM
Why wont my variables export? suerevans Linux - Newbie 5 04-05-2004 04:46 AM
really easy question: why won't my environment variables export digitized_funk Linux - Newbie 3 10-22-2003 06:22 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:58 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration