How to change environment variable in shell executing a C program from that C program?
问题 I want to change the value of PATH variable inside the C program and then see the changed value in the shell using which I run this program. Doing something like this, #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> int main () { char *path = getenv ("PATH"); printf ("%s\n\n", path); setenv ("PATH", strcat (path, ":~/myNewPath/"), 1); printf ("%s\n\n", path); int pid = fork (); if (pid == -1) abort (); if (pid == 0) { } else { // use execlp? how? source? any