environment variable in linux gcc

Link to this post 23 May 13

I am able to get environment variable using getenv function in gcc.But when tried to change the value using setenv function, its value is changed as seen after calling getenv function. when try to seen the value of environment variable in command terminal in ubuntu. it is not showing any change. Can any one tell me, how can i change environment variable in linux gcc.

Linux Learner

Link to this post 30 Apr 14

Many UNIX-based (and other) systems create a child process to run programs, so any changes that you make will affect only the environment running your program, not the process (terminal window) that started the program. You can see what I mean by running "ps" in a terminal/shell window: one process listing will show the name of the shell running in your terminal window, while the other listing shows the "ps" command.

I'm just getting back into a UNIX-type environment (yay, Mint!), so the only solutions to your problem that I remember is by (ugh! ugh!) running a root-level program that can manipulate system memory; or run a script or program that initializes the environment variables that you want to manipulate in a child process, then start another child process that will work with the environment variables.


#this is a script that sets up the variables that program "foo" will manipulate.
set RESULT1=' '
set RESULT2='0'
echo $RESULT1
echo $RESULT2
# end shell script

Write a program (foo) that changes the environment variables, and the value of the changed variables will stay in effect until the shell script ends.

Who we are ?

The Linux Foundation is a non-profit consortium dedicated to the growth of Linux.

More About the foundation...

Frequent Questions

Join / Linux Training / Board