environment variables

hi,

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).

thanks & regards
sumsin.

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?

thanks & regards
sumsin

The reason source works: it runs the script in the same (parent) process. So when it's done with the sourced script the variables are still there.

Yes, put the script in your profile.

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...

If you're changing the variables in your program, do you want the final "result" to be available to the parent?

Then try:
setenv() in your code AND open a file, call it newvar.sh, write the new version of the variables to it every time you "edit" the variables.

Execute the C code in a script like this:

cd /path/to/working_directory
./my_c_code
chmod +x ./newvar.sh
.  ./newvar.sh