Re: How do I ex****t a environmental variable to a C program?
by jt@[EMAIL PROTECTED]
(Jens Thoms Toerring)
May 9, 2008 at 05:45 PM
iavian <vijay@[EMAIL PROTECTED]
> wrote:
> I want to set a env variable in a C program? . Not through shell env
> variables. Any help?
This is not a C question since this only depends on how your
shell handles things. But, that out of the way, you simply
can't do that (at least with no shell I ever heard of). Your
C program is a process started by your shell and such a child-
process can never change anything in its "parent" process.
The only thing you can do is to have the the program output
something the shell then explicitely executes, like (e.g.
using bash):
---- env_cmd.c -----
#include <stdio.h>
int main( void )
{
puts( "ex****t X=AAA" );
return 0;
}
--------------------
and then do e.g.
> gcc -o env_cmd env_cmd.c
> `./env_cmd` # note the backticks
> echo $X
AAA
Regards, Jens
--
\ Jens Thoms Toerring ___ jt@[EMAIL PROTECTED]
\__________________________ http://toerring.de