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 10-21-2003, 10:19 PM   #1
digitized_funk
Member
 
Registered: Sep 2002
Location: Australia
Distribution: Suse 8.0
Posts: 50

Rep: Reputation: 15
really easy question: why won't my environment variables export


I'm trying to export some variables from .bash_profile but when I run the script it just won't export them, I've tried everything I know which isn't much:

# User specific environment and startup programs

echo "Bash Profile Script Starting..."
#Set up environment variables
QTDIR=/usr/lib/qt3
echo $QTDIR
export QTDIR


running it:
[rg@pc-ug19-10 rg]$ .bash_profile
Bash Profile Script Starting...
/usr/lib/qt3
[rg@pc-ug19-10 rg]$ echo $QTDIR

[rg@pc-ug19-10 rg]$


cheers...
 
Old 10-22-2003, 01:06 AM   #2
slakmagik
Senior Member
 
Registered: Feb 2003
Distribution: Slackware
Posts: 4,113

Rep: Reputation: Disabled
Are you trying this from an xterm? You probably just need to run 'rxvt -ls' (or whatever) and then do 'echo $QTDIR'. If not, login and logout - or do whatever it is that gets bash to reread it's initialization files.

Oh, if you want to do it on the fly, rather than modifying bash_profile, just typing 'export QTDIR=/usr/lib/qt3' or whatever should work. But that's a one-time thing.

Last edited by slakmagik; 10-22-2003 at 01:11 AM.
 
Old 10-22-2003, 01:17 AM   #3
maroonbaboon
Senior Member
 
Registered: Aug 2003
Location: Sydney
Distribution: debian
Posts: 1,495

Rep: Reputation: 48
The exporting is done to subprocesses started by the shell. So when your bash_profile is run by the login shell all your processes should get the exported variables OK. But in your example you are invoking a new shell to execute the commands in there. When this shell terminates, the values are lost.

I think that's what's happening anyway

To see what I mean do:

% foo=bar
% xterm &
(now try 'echo $foo' in the xterm - no value...)
% export foo
% xterm &
(now try 'echo $foo' again in new xterm, should see the value).

Last edited by maroonbaboon; 10-22-2003 at 01:28 AM.
 
Old 10-22-2003, 05:22 AM   #4
UltimaGuy
Member
 
Registered: Aug 2003
Location: Chennai, India
Distribution: PCLinuxOS .92, FC4
Posts: 840

Rep: Reputation: 32
You have to type "source <filename>" in order to update an running shell using this method. Otherwise, as maroonbaboon pointed out, your script will fork out a new shell and execute the commands in that shell, and worse, kill that thread when the script is over.
 
  


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
why do we have to export variables? learnfast Linux - Newbie 2 05-27-2005 08:27 AM
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

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

All times are GMT -5. The time now is 12:34 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