start page | rating of books | rating of authors | reviews | copyrights

Unix Power ToolsUnix Power ToolsSearch this book

24.4. Subshells

In Unix, when a program starts another program (more exactly, when a process starts another process), the new process runs as a subprocess (Section 24.3) or child process.[70] When a shell starts another shell, the new shell is called a subshell.[71]

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

[71]When you use the shell's exec (Section 35.5) 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, and 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. Section 35.16 explains how exit sets a shell's exit status.

-- JP



Library Navigation Links

Copyright © 2003 O'Reilly & Associates. All rights reserved.