I´m making a very simple scratch of a shell. The father process prints out the current working directory and waits for some user input. For each user input, it creates a child process to execute the specified command and pass to it the **environ variable. I´m using execve. I created a cd program to change the current directory. It changes the current directory to the specified and updates the PWD environment variable to the new value. But when this child process finish and the father prints out the current working directory again, the PWD seens to be the same as before the changing by the cd child process.
So I dint manage to make the parent process get the environment changed by the child.
How can I do that?
To clarify a little bit, here is a code snippet
-------------
Father(shell)
-------------
extern char **environ;
void main()
{
(...)
do {
path = getenv("PWD");
printf("\n[%s]# ", path);
}
while (true)
}
-------------
Child (cd)
-------------
extern char **environ;
int main(int argc, char *argv[])
{
char cwd[100],
*newDir;
if (argc == 1)
{
newDir = getenv("HOME");
chdir(newDir);
}
else
{
newDir = argv[1];
chdir(newDir);
}
setenv("PWD", newDir, 1);
}