2023-04-15 13:23:49 +02:00
====== Grouping commands in a subshell ======
===== Synopsis =====
2023-04-15 13:53:05 +02:00
< code >
( < LIST > )
< / code >
2023-04-15 13:23:49 +02:00
===== Description =====
2023-04-15 13:53:05 +02:00
The [[syntax:basicgrammar#lists|list]] ''< LIST > '' is executed in a separate shell - a subprocess. No changes to the environment (variables etc...) are reflected in the " main shell" .
2023-04-15 13:23:49 +02:00
===== Examples =====
Execute a command in a different directory.
2023-04-15 13:53:05 +02:00
< code bash >
2023-04-15 13:23:49 +02:00
echo " $PWD"
( cd /usr; echo " $PWD" )
echo " $PWD" # Still in the original directory.
2023-04-15 13:53:05 +02:00
< / code >
2023-04-15 13:23:49 +02:00
===== Portability considerations =====
* The subshell compound command is specified by POSIX.
* Avoid ambiguous syntax.
2023-04-15 13:53:05 +02:00
< code bash >
2023-04-15 13:23:49 +02:00
(((1+1))) # Equivalent to: (( (1+1) ))
2023-04-15 13:53:05 +02:00
< / code >
2023-04-15 13:23:49 +02:00
===== See also =====
* [[syntax:ccmd:grouping_plain | grouping commands]]
* [[http://mywiki.wooledge.org/SubShell | Subshells on Greycat's wiki]]