I'm trying to write an install script for my Amazon servers and I'm getting stuck on some environment variable issues. I have a set of scripts to configure things and some of them depend on environment variables that I create in profile.d scripts. I create the profile.d script (or copy it over) and need to use the variables it sets in scripts that run later (without logging out and back in).
Is there a way to load these (in a script) so future scripts take advantage of them?
In the script after I create the file I tried:
source /etc/profile.d/scriptname.sh
and
. /etc/profile.d/scriptname.sh
but it only sets the environment variable for the duration of the currently running script, so any other script that gets run later can't use the values being set. How do I get them to get set for the session instead of the script?
I have one master script that calls a series of small scripts to do all the configurations.
Environmental variables are inherited. So you will need to source the profile scripts at the top of the master script.