2012-06-06 63 views

回答

2

看看getenv()setenv();例如:

char *shell; 


/* Get the path of the current shell to start it later */ 
shell = getenv("SHELL"); 
if (shell == NULL) { 
    fprintf(stderr, "Error eding SHELL env. var.\n"); 
    return 1; 
}  

/* Overwrite env. var. PATH */ 
if (setenv("PATH", "/usr/bin", 1) < 0) { 
    fprintf(stderr, "Error setting env. var.\n"); 
    return 1; 
}