Subshells

In UNIX, when a program starts another program (more exactly, when a process starts another process), the new process runs as a subprocess () or child process. [1] When a shell starts another shell, the new shell is called a subshell. [2]

[1] This isn't true when the subprocess is execd from the parent process without a fork first. Article explains.

[2] When you use the shell's exec () command, it does not start a subprocess.

So what? There are some important things to know about it: the child process gets a copy of its parent's environment. Any changes in the environment of the child process aren't passed to its parent. "Still," I hear you say, "so what??"

If you use the exit command, a subshell (or any shell) will terminate. In a script, when the shell reads the end of file, that does an implicit exit. On the command line, an end-of-input character (usually CTRL-d) will do the same thing. Article explains how exit sets a shell's exit status.

- JP