LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 05-27-2005, 06:53 AM   #1
learnfast
Member
 
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.

Thanks.
 
Old 05-27-2005, 07:24 AM   #2
mlangdn
Senior Member
 
Registered: Mar 2005
Location: Kentucky
Distribution: Slackware64-current
Posts: 1,845

Rep: Reputation: 452Reputation: 452Reputation: 452Reputation: 452Reputation: 452
export VARIABLE

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, 08:27 AM   #3
kees-jan
Member
 
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.

Groetjes,

Kees-Jan
 
  


Reply



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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:55 AM.

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