5.14. Subshells or Child ShellsWhen you log into a Linux system, you execute an initial login shell. This initial shell executes any simple commands that you enter. However, there are several circumstances when your current shell (the parent process) creates a new shell (a child process) to perform some tasks:
A child shell is often called a subshell. Just like any other Linux process, a subshell has its own current working directory, and so cd commands executed in a subshell do not affect the working directory of the parent shell: $ pwd ...display my login shell's current dir. /home/glass $ (cd /; pwd) ...the subshell moves and executes pwd. / ...output comes from the subshell. $ pwd ...my login shell never moved. /home/glass $ _ Every shell contains two data areas: an environment space and a local variable space. A child shell inherits a copy of its parent's environment space and a clean local variable space (Figure 5-10). Figure 5-10. Child shell data spaces.
|