I want to create a new EV(Environment Variable) through a c program and I done this thing through setenv() method. But the newly created EV is not permanent, i.e. when I exit from the program the EV also no longer lives. But I want to make it a permanent EV for the current user. Actually I am getting all the environment variables through envp (the environment variable pointer, it is the list of all the EVs).
It is not possible to create an environment variable in a child proces (what you are in when you are running code) and have the parent shell be able to see it. Once the code exits, the variable is gone with the defunct process.
but what I am thinking that ... I write these variables in one of my private file say ".myprogram_profile" at $HOME dir, then source this private file in .bash_profile so that the newly created variables comes in effect.
am i right?
or i should think some other approach.
what do u say?
I think,
though the variables are available they are in effect only to the child(running process which created the EV variables) and not in effect to the parent ( shell ) which forked by the child.
Wont the newly added Env variables be effected with respect to the parent only after running the .profile ----> .$HOME/.profile?
but is there any other way to do so?
Because when I create a variable two or more times it is added that many time in the file.
And I also wnat to edit the variables through my program...