I wrote a C program in Linux to set the values of environment variables using setenv
, but after execution, when I run set
or export
, the environment variable itself seems to be unset. Why?
Here is the code snippet:
int main()
{
char *mallocPtr, *callocPtr, *reallocPtr, *memalignPtr, *vallocPtr;
struct sigaction sa;
sa.sa_handler=SIGSEGV_handler;
sigaction(SIGSEGV, &sa, NULL);
if(setenv("ENV1", "3", 1) == 0)
printf("ENV1 set to 3
");
else
fprintf(stderr, "setenv failed on ENV1");
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…