21 August 2021

Bash provides two ways to group a list of commands to be executed as a unit:
* () : create a subshell environment and each of the commands in list to be executed in that subshell;
* {} : list of commands, separated by semicolon or newline, to be executed in the current shell context no subshell is created

Note: all example below are execute in a container:

docker run -it  ubuntu /bin/bash

()

In this example you can see that the current directory has no changed at the end of () and a file parentheses.txt is created

$ pwd
/

$ (cd tmp && touch parentheses.txt)

$ pwd
/

$ ls -latr /tmp/parentheses.txt
-rw-r--r-- 1 root root 0 Aug 21 04:34 /tmp/parentheses.txt

{}

In this example you can see that the current directory has been changed at the end of {} and a file curly.txt is created

$ pwd
/

$ { cd tmp; touch curly.txt; }

$ pwd
/tmp

$ ls -latr /tmp/curly.txt
-rw-r--r-- 1 root root 0 Aug 21 04:36 /tmp/curly.txt

References