mirror of
https://github.com/rawiriblundell/wiki.bash-hackers.org
synced 2024-12-25 22:20:39 +01:00
36 lines
746 B
Markdown
36 lines
746 B
Markdown
|
# Grouping commands in a subshell
|
||
|
|
||
|
## Synopsis
|
||
|
|
||
|
( <LIST> )
|
||
|
|
||
|
## Description
|
||
|
|
||
|
The [list](/syntax/basicgrammar#lists) `<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.
|
||
|
|
||
|
``` bash
|
||
|
echo "$PWD"
|
||
|
( cd /usr; echo "$PWD" )
|
||
|
echo "$PWD" # Still in the original directory.
|
||
|
```
|
||
|
|
||
|
## Portability considerations
|
||
|
|
||
|
- The subshell compound command is specified by POSIX.
|
||
|
- Avoid ambiguous syntax.
|
||
|
|
||
|
``` bash
|
||
|
(((1+1))) # Equivalent to: (( (1+1) ))
|
||
|
```
|
||
|
|
||
|
## See also
|
||
|
|
||
|
- [grouping commands](/syntax/ccmd/grouping_plain)
|
||
|
- [Subshells on Greycat's wiki](http://mywiki.wooledge.org/SubShell)
|