mirror of
https://github.com/flokoe/bash-hackers-wiki.git
synced 2024-11-29 01:13:41 +01:00
32 lines
809 B
Plaintext
32 lines
809 B
Plaintext
|
====== Grouping commands in a subshell ======
|
||
|
|
||
|
===== Synopsis =====
|
||
|
<code>
|
||
|
( <LIST> )
|
||
|
</code>
|
||
|
|
||
|
|
||
|
===== Description =====
|
||
|
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".
|
||
|
|
||
|
===== Examples =====
|
||
|
|
||
|
Execute a command in a different directory.
|
||
|
<code bash>
|
||
|
echo "$PWD"
|
||
|
( cd /usr; echo "$PWD" )
|
||
|
echo "$PWD" # Still in the original directory.
|
||
|
</code>
|
||
|
|
||
|
===== Portability considerations =====
|
||
|
|
||
|
* The subshell compound command is specified by POSIX.
|
||
|
* Avoid ambiguous syntax.
|
||
|
<code bash>
|
||
|
(((1+1))) # Equivalent to: (( (1+1) ))
|
||
|
</code>
|
||
|
|
||
|
===== See also =====
|
||
|
* [[syntax:ccmd:grouping_plain | grouping commands]]
|
||
|
* [[http://mywiki.wooledge.org/SubShell | Subshells on Greycat's wiki]]
|