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 hints?
}
return 0;
}
If I use source
command in the exec*
system call. What will be the syntax to update this PATH
variable in the shell backwards?