PDA

View Full Version : How to check and change environment variables in C



edugarcia
09-29-2004, 12:51 PM
Hi,

I want to know how can I change and check environment variables in a C program. For instance I want to check $HOME or $PATH an change them

Thanks in advance

Perspective
09-29-2004, 12:56 PM
getenv() and setenv()

check your man pages for these functions.

jim mcnamara
09-29-2004, 03:39 PM
It's putenv(). :D

Perspective
09-29-2004, 06:42 PM
It's putenv(). :D

setenv() gives you more control, check your man pages ;)

Salem
09-30-2004, 01:10 AM
But neither of them change the parent environment.

If you program does putenv("PATH=foo");
Then running the program does NOT change the PATH in your shell.

jim mcnamara
09-30-2004, 10:51 AM
Because you are running in a child process.

edugarcia
10-01-2004, 11:26 AM
Thanks guys. Linux rules