wiki.bash-hackers.org/syntax/ccmd/grouping_subshell.md
2023-04-16 20:04:24 +12:00

746 B

Grouping commands in a subshell

Synopsis

( <LIST> )

Description

The list <LIST> is executed in a separate shell - a subprocess. No changes to the environment (variables etc...) are reflected in the "main shell".

Examples

Execute a command in a different directory.

echo &quot;$PWD&quot;
( cd /usr; echo &quot;$PWD&quot; )
echo &quot;$PWD&quot; # Still in the original directory.

Portability considerations

  • The subshell compound command is specified by POSIX.
  • Avoid ambiguous syntax.
(((1+1))) # Equivalent to: (( (1+1) ))

See also