LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Why can't my scripts set environment variables? (https://www.linuxquestions.org/questions/linux-software-2/why-can%27t-my-scripts-set-environment-variables-223597/)

Matthew3 08-28-2004 03:12 PM

Why can't my scripts set environment variables?
 
Greetings. This is my first post on this forum. I am trying to make my computer set some environment variables as follows (the exact variables aren't really important for this question):

CPPFLAGS='-I/opt/glibmm/include -I/opt/gtk/include -I/opt/gtkmm/include -I/opt/libsigc++/include -I/opt/xine-lib/include $CPPFLAGS'
LDFLAGS='-L/opt/glibmm/lib -L/opt/gtk/lib -L/opt/gtkmm/lib -L/opt/libsigc++/lib -L/opt/xine-lib/lib $LDFLAGS'
PKG_CONFIG_PATH='/opt/glibmm/lib/pkgconfig:/opt/gtk/lib/pkgconfig:/opt/gtkmm/lib/pkgconfig:/opt/libsigc++/lib/pkgconfig:/opt/xine-lib/lib/pkgconfig:$PKG_CONFIG_PATH'
LD_LIBRARY_PATH='/opt/glibmm/lib:/opt/gtk/lib:/opt/gtkmm/lib:/opt/libsigc++/lib:/opt/xine-lib/lib:$LD_LIBRARY_PATH'
PATH='/opt/gtk/bin:/opt/xine-lib/bin:/opt/xine-ui/bin:$PATH'
export CPPFLAGS LDFLAGS PKG_CONFIG_PATH LD_LIBRARY_PATH PATH

If I paste these lines into the shell, they work for that instance of the shell. When I restart the shell, I must repaste them. If I put them in ~/.bash_profile, they have no effect. If I put them into a file and run that file, it has no effect whatsoever. What am I doing wrong?

I'm using Fedora Core 2 if that makes any difference.

Thanks in advance!

david_ross 08-28-2004 03:16 PM

Welcome to LQ.

They will only last for the duration of that script. You will need to source the script into your shell using iether of:
source /path/to/script
. /path/to/script

Matthew3 08-28-2004 03:45 PM

Thanks! That made the script commands work as I wanted (I also had to change my apostrophes to quotes). What is the best way to make the script run every time I open the console if I only want it to apply to my account?

rhorn 08-28-2004 04:20 PM

Try putting them in your ~/.bashrc script instead.

mikshaw 08-28-2004 04:24 PM

If you put them in ~/.bash_profile they'll take effect the next time you log in. bash_profile is a good way to set variables to be available from any shell.
bashrc will only set variables for non-login shells, unless you have "source $HOME/.bashrc" in ~/.bash_profile

Matthew3 08-28-2004 05:26 PM

Putting it in ~/.bashrc worked. Thanks!


All times are GMT -5. The time now is 10:27 PM.