2023-07-05 11:43:35 +02:00
|
|
|
# Grouping commands in a subshell
|
|
|
|
|
|
|
|
## Synopsis
|
|
|
|
|
|
|
|
( <LIST> )
|
|
|
|
|
|
|
|
## Description
|
|
|
|
|
2024-01-29 02:07:56 +01:00
|
|
|
The [list](../../syntax/basicgrammar.md#lists) `<LIST>` is executed in a
|
2023-07-05 11:43:35 +02:00
|
|
|
separate shell - a subprocess. No changes to the environment (variables
|
2024-10-08 06:00:17 +02:00
|
|
|
etc...) are reflected in the "main shell".
|
2023-07-05 11:43:35 +02:00
|
|
|
|
|
|
|
## 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
|
|
|
|
|
2024-01-29 02:07:56 +01:00
|
|
|
- [grouping commands](../../syntax/ccmd/grouping_plain.md)
|
2024-03-30 19:22:45 +01:00
|
|
|
- [Subshells on Greycat's wiki](http://mywiki.wooledge.org/SubShell)
|