A subshell creates a separate instance of the command processor or a subprocess of the parent shell by wrapping a command in parentheses. Any started subshell inherits the parent shell’s working directory, but directory changes do not carry back over to its parent. Because of that, subshells are ideal for running one-off commands in a different directory:
$ pwd /Users/jeff/conway/ $ (cd www && npm install) [...] $ pwd /Users/jeff/conway/
In this example, the command is run in the
www directory but the main shell is in the same place after the command completes.
--prefixflag that allows running the command in another directory. Instead of using a subshell you could also run
npm install --prefix wwwand get the same result.