LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 09-13-2005, 02:36 AM   #1
balteo
LQ Newbie
 
Registered: Jul 2002
Posts: 27

Rep: Reputation: 15
Basic question about exporting shell variables


Hello,
I did the following:
1. I set a shell variable as follows un shell one:
"MYVAR=foo"
2. I printed the value of MYVAR in the same shell (shell one) as follows:
"echo $MYVAR"
3. I exported the variable so that it be available in other shells (from shell one):
"export MYVAR"
4. I then tried to display the value of MYVAR in an another shell (shell two) as follows:
"echo $MYVAR" and I get a blank line...
Can anyone help me? I thought that by exporting the variable it became a global variable instead of remaining a local variable...
Any help welcome,
Julien.
 
Old 09-13-2005, 02:48 AM   #2
nixcraft
Member
 
Registered: Nov 2004
Location: BIOS
Distribution: RHEL3.0, FreeBSD 5.x, Debian 3.x, Soaris x86 v10
Posts: 379

Rep: Reputation: 30
Hope you are using same shell that is /bin/bash, here is what I did and got correct values:

a=test
echo $a
test
export a
/bin/bash
echo $a
test
 
Old 09-13-2005, 11:48 AM   #3
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 374Reputation: 374Reputation: 374Reputation: 374
Environment variables created with export are only inherited by child processes. What that means is, if you have a shell that exports a variable, only that shell and processes started from that shell will have that variable. The variable doesn't "spread" to existing shells because it was exported.
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
exporting variables gecoool Programming 2 10-25-2005 01:17 AM
Exporting variables through scripts rammya Programming 1 04-14-2004 10:24 AM
exporting variables under bash isn't working! dtheorem Programming 6 03-11-2004 08:35 AM
exporting variables in Perl nbp Programming 1 11-18-2003 08:35 AM
exporting global variables neo77777 Programming 6 09-18-2002 01:46 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 12:36 PM.

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