|
2011-09-01
, 14:22
|
Posts: 3,617 |
Thanked: 2,412 times |
Joined on Nov 2009
@ Cambridge, UK
|
#2
|
|
2011-09-01
, 14:29
|
Posts: 451 |
Thanked: 334 times |
Joined on Sep 2009
|
#3
|
|
2011-09-01
, 15:08
|
Posts: 151 |
Thanked: 93 times |
Joined on Sep 2009
@ sofia, bulgaria
|
#4
|
|
2011-09-01
, 19:09
|
Posts: 726 |
Thanked: 345 times |
Joined on Apr 2010
@ Sweden
|
#5
|
|
2011-09-01
, 19:36
|
Posts: 451 |
Thanked: 334 times |
Joined on Sep 2009
|
#6
|
|
2011-09-01
, 19:40
|
Posts: 451 |
Thanked: 334 times |
Joined on Sep 2009
|
#7
|
Environment variables are, by definition, bound to a certain process.
If you spawn a child process, it inherits the environment.
So, if you want your changes to stay available you need to run the process in the same environment as the one you changed.
|
2011-09-01
, 20:48
|
Posts: 726 |
Thanked: 345 times |
Joined on Apr 2010
@ Sweden
|
#8
|
#include <unistd.h> #include <stdlib.h> #include <stdio.h> extern char **environ; int main() { printf("environ[0]: %s\n", environ[0]); printf("PATH: %s\n", getenv("PATH")); if(!setenv("PATH", "/my/new/path", 1)) { printf("PATH: %s\n", getenv("PATH")); } else { printf("Could not change PATH variable!\n"); } return 0; }
The Following User Says Thank You to Joorin For This Useful Post: | ||
|
2011-09-02
, 05:27
|
Posts: 451 |
Thanked: 334 times |
Joined on Sep 2009
|
#9
|
|
2011-09-02
, 06:19
|
Posts: 151 |
Thanked: 93 times |
Joined on Sep 2009
@ sofia, bulgaria
|
#10
|
The exec() family of functions replaces the current process image with a new process image.
The Following User Says Thank You to lidow For This Useful Post: | ||
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:
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
But if I create a shell script with just
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.