-   Linux - Newbie (
-   -   really easy question: why won't my environment variables export (

digitized_funk 10-21-2003 11:19 PM

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
echo $QTDIR
export QTDIR

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

[rg@pc-ug19-10 rg]$


slakmagik 10-22-2003 02:06 AM

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.

maroonbaboon 10-22-2003 02:17 AM

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).

UltimaGuy 10-22-2003 06:22 AM

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.

All times are GMT -5. The time now is 06:40 AM.