Cancel

Subshell/Grouping in Bash

A Subshell/Grouping can be used to do parallel processing. When you run a script, it creates a new process called Subshell, and your script will get executed using a Subshell.

First execute everything within the round brackets, then insert data into the file.

1
(echo "Hello"; echo "World") > demo1.txt

Any kind of command can be added inside the round brackets.

1
(ls -1; echo "World") > demo3.txt

Here is your example.

1
2
3
4
5
6
7
8
9
# Create a folder first.
mkdir demo_folder

# Round brackets will let you go inside the folder without showing you.
# it will create a few files and come back from the folder automatically.
(cd demo_folder ; touch my-demo-{1..5}.txt)

# verify
ls demo_folder