Setting environment variables within a C program.

Joseph S. D. Yao jsdy at hadron.UUCP
Tue May 7 12:50:00 AEST 1985


>  freds_wife = Wilma
>  export fred_wife
> How do I change the value of freds_wife from Wilma to Betty within the C
> program, and get the environment to understand the change later?

You can't.  Environment variables are exported to children, not vice-
versa.  The C prog is child of the shell.  However, if the program
produces no other output, you can get the shell to change itself by
printing out the commands:
	printf("freds_wife=Betty; export freds_wife\n");
and then:
	$ eval `prog`
This can be used profitably with, e.g., 'tset' to set TERM and TERMCAP.

However, a second, more difficult obstacle is that Betty loves Barney
and Wilma won't divorce Fred.	;-)

	Joe Yao		hadron!jsdy at seismo.{ARPA,UUCP}



More information about the Comp.unix.wizards mailing list