Subshells

Commands placed between parentheses are executed in a new child shell process rather than the shell process that received the commands as input.

This can be useful if you want a command to run in a different directory or with other alterations to its environment, without affecting the current shell process.

shell-prompt: (cd /etc; ls)
        

Since the commands above are executed in a new shell process, the shell process that printed "shell-prompt: " will not have its current working directory changed. This command has the same net effect as the following:

shell-prompt: pushd /etc
shell-prompt: ls
shell-prompt: popd
        
Practice

Note

Be sure to thoroughly review the instructions in Section 2, “Practice Problem Instructions” before doing the practice problems below.
  1. Show a single Unix command that runs pwd and produces the output "/etc", without changing the CWD of the shell process.