subshell
A child copy of the current shell, created by ( ), by command substitution and by each stage of a pipe.
In more detail
It starts with the same variables, functions and directory, but anything it changes is lost when it exits. (cd dir && make) runs in a subshell so your own directory does not move. The same effect is why a counter incremented inside cmd | while read loses its value after the loop.
Related terms
- child process — A process started by another process, its parent, from which it inherits a copy of the environment and current directory.
- command substitution — Running a command inside $( ) and replacing it with that command's standard output, as in today=$(date).
- pipe — The | operator, which connects one command's standard output to the next command's standard input so they run together.
- process substitution — The bash form <(command), which runs a command and hands its output to another program as if it were a file name.
Taught in
- Which Shell Am I In, And Getting Bash Five — Bash Scripting & Command Line Automation
- The Field Separator, And Reading Lines Safely — Bash Scripting & Command Line Automation
- Command Substitution And Subshells — Bash Scripting & Command Line Automation
- Script Input And Output: read, Heredocs, printf — Bash Scripting & Command Line Automation