Question: Setting Environment Variables in C

Question: Setting Environment Variables in C

Post by Nathan Do » Sun, 05 Apr 1992 02:54:25



How do you set an environment variable from within a C
program that will take effect in the calling environment?

Assume I have a C program called changenv which takes two
arguments: an environment variable name and the new value.

csh> setenv TEST test_value
csh> echo $TEST
test_value
csh> changenv TEST new_test_value
csh> echo $TEST
new_test_value

How do I write this 'changenv' program in C?  Is it possible?

-------------------------------------------------------------
Nathan Doss

NSF Engineering Research Center

 
 
 

1. Question: How to set environment variables from a c program?

I've searched the FAQ's and I've read the books, and I still cannot
find a way to set an environment variable from within a c program
and have that change be reflected in the current user's shell.
(Although I'm hardly an expert at this sort of thing.)

Note that this is not a source (csh) or "." (bsh,sh) problem. In fact
I have tried to write a temporary file and then source or "." the file
that contains the envrionment setting using the system subroutine, but that
does not do the trick.

Any ideas, suggestions, solutions or examples would be greatly appreciated.

cross-postings. Thanks in advance.

--
jim warsa
albuquerque

2. Reading is much more interesting than TV (0500/1708)

3. easy question : how to set an environment variable ?

4. Kernel 2.2.19 compile error !!! (ftap_syms.c)

5. Question: How to set environment variables

6. how to setup loopback before calling mount_root() .. root=/dev/loop0

7. Why does the cgi environment not inherit environment variables?

8. Mac fileserver for Linux?

9. how to export shell environment variables to the primary environment?

10. Setting variables in a variable array of null variables

11. Setting environment variables (netscape enterprise server/aix)

12. Setting Shell Environment Variables from Within C Programs

13. Dynamically setting environment variables on apache startup?