What is Shell and Sub Shell in Bash Script
What Is Shell And Sub Shell In Bash Script
Shell: Shell scripting is a powerful tool for automating tasks and simplifying the management of systems and applications. One important concept in shell scripting is the use of subshells, which allow you to execute commands within a separate shell environment. Subshell: A subshell is a child shell that is spawned by the main shell (also known as the parent shell). It is a separate process with its own set of variables and command history, and it allows you to execute commands and perform operations within a separate environment.
Procedure Steps:
Step 1: Check the OS version by using following command.
root@linuxhelp:~# lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux 12 (bookworm)
Release: 12
Codename: bookworm
Step 2: Create a file for create a script by using following command.
root@linuxhelp:~# vim subshell
#!/bin/bash
# Show the Current Directory in the parent shell
pwd
# Create a subshell and Change to a different directory
( cd /home/linuxhelp ; pwd )
# The Current directory in the parent shell is unchanged.
pwd
Step 3: Give the Executable permission to the script file by using following command.
root@linuxhelp:~# chmod +x subshell
Step 4: Long list files to check file permission by using following command.
root@linuxhelp:~# ls -la
total 40
drwx------ 4 root root 4096 Sep 25 05:43 .
drwxr-xr-x 19 root root 4096 Sep 16 00:52 ..
-rw------- 1 root root 653 Sep 25 05:36 .bash_history
-rw-r--r-- 1 root root 571 Apr 11 2021 .bashrc
drwx------ 2 root root 4096 Sep 12 00:35 .cache
-rw-r--r-- 1 root root 161 Jul 9 2019 .profile
drwx------ 2 root root 4096 Sep 12 00:17 .ssh
-rwxr-xr-x 1 root root 52 Sep 25 05:43 subshell
-rw------- 1 root root 7255 Sep 25 05:43 .viminfo
Step 5: Run the script file by using following command.
root@linuxhelp:~# ./subshell
/root
/home/linuxhelp
/root
Conclusion:
We have reached the end of this article. In this guide, we have walked you through the steps required to Create Shell and Sub Shell in Bash Script on Debian 12. Your feedback is much welcome
Comments ( 0 )
No comments available