View Single Post
Posts: 451 | Thanked: 334 times | Joined on Sep 2009
#1
I have customized PATH, CFLAGS, etc many variables in .profile, which get changed dynamically upon copying files to certain directories.

After I do this, to make the system aware, I source ~/.profile again, which makes it reread these dirs.

I've been busting my brains, how to call:
Code:
. ~/.profile
from a shell script and have the exported environment variables stay in the system, after this shellscript has run. Can anyone help me?

What I mean is, for instance: say .profile reads ~/bin for subdirs and then adds these to the PATH

So I source it now, it only has one subdir, so only ~/bin/1 gets added to the PATH

Let's say I create ~/bin/2, and now I need to source ~/.profile to add ~/bin/1 and ~/bin/2 to PATH

If I open a terminal and run
Code:
. ~/.profile
all's fine and the PATH contains the proper dirs.

But if I create a shell script with just
Code:
. ~/.profile
and then run
Code:
./shellscript.sh
the PATH gets exported within the script, but once it finishes running the PATH in the term is obviously not affected by the export.

I want to source .profile in a shellscript somehow and have the resultant exported variables remain exported after the shellscript has finished running.

Can I do this somehow? Can't figure out how...

Thanks for advice.