| Next | Unix Command Internals | 17 |
Here's the original shell, with its idea of the current directory

When we run ./do-cd, the shell forks a subshell to run the script

The subshell runs the cd command

Then the subshell forks again so it can run pwd

pwd reports that the current directory is /tmp, and exits
Then the subshell exits

The original shell never cded anywhere
| Next | ![]() |
Copyright © 2002 M. J. Dominus |