How to create a Shell and Subshell on Rocky Linux 9.2
To create a Shell and Subshell on Rocky Linux 9.2
Introduction:
Shell is an environment in which we can run our commands, programs, and shell scripts. There are different flavors of a shell, just as there are different flavors of operating systems. Each flavor of shell has its own set of recognized commands and functions.
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 allows you to execute commands and perform operations within a separate environment.
Procedure:
Step 1: Check the OS version by using the below command.
**[root@Linuxhelp ~]# cat /etc/os-release**
NAME="Rocky Linux"
VERSION="9.2 (Blue Onyx)"
ID="rocky"
ID_LIKE="rhel centos fedora"
VERSION_ID="9.2"
PLATFORM_ID="platform:el9"
PRETTY_NAME="Rocky Linux 9.2 (Blue Onyx)"
ANSI_COLOR="0;32"
LOGO="fedora-logo-icon"
CPE_NAME="cpe:/o:rocky:rocky:9::baseos"
HOME_URL="https://rockylinux.org/"
BUG_REPORT_URL="https://bugs.rockylinux.org/"
SUPPORT_END="2032-05-31"
ROCKY_SUPPORT_PRODUCT="Rocky-Linux-9"
ROCKY_SUPPORT_PRODUCT_VERSION="9.2"
REDHAT_SUPPORT_PRODUCT="Rocky Linux"
REDHAT_SUPPORT_PRODUCT_VERSION="9.2"
Step 2: Create a script file named testscript.sh by using the below command.
[root@Linuxhelp ~]# touch testscript.sh
Step 3: Long list the files by using the below command.
[root@Linuxhelp ~]# ll
total 4
-rw-------. 1 root root 1039 Aug 13 22:24 anaconda-ks.cfg
drwxr-xr-x. 2 root root 6 Aug 13 22:33 Desktop
drwxr-xr-x. 2 root root 6 Aug 13 22:33 Documents
drwxr-xr-x. 2 root root 6 Aug 13 22:33 Downloads
drwxr-xr-x. 2 root root 6 Aug 13 22:33 Music
drwxr-xr-x. 2 root root 6 Aug 13 22:33 Pictures
drwxr-xr-x. 2 root root 6 Aug 13 22:33 Public
drwxr-xr-x. 2 root root 6 Aug 13 22:33 Templates
-rw-r--r--. 1 root root 0 Sep 15 20:42 testscript.sh
drwxr-xr-x. 2 root root 6 Aug 13 22:33 Videos
Step 4: Give executable permission to testscript.sh file by using the below command.
[root@Linuxhelp ~]# chmod +x testscript.sh
Step 5: Open testscript.sh file and Add the following Lines by using the below command.
[root@Linuxhelp ~]# vim testscript.sh
# !/bin/bash
echo script has begin
ping -c 10 192.168.6.130
cat testscript.sh
echo script has been ended......
Step 6: Execute the following script to ping the IP address 10 times and view the testscript.sh file by using the below command.
[root@Linuxhelp ~]# ./testscript.sh
script has begin
PING 192.168.6.130 (192.168.6.130) 56(84) bytes of data.
64 bytes from 192.168.6.130: icmp_seq=1 ttl=64 time=0.129 ms
64 bytes from 192.168.6.130: icmp_seq=2 ttl=64 time=0.646 ms
64 bytes from 192.168.6.130: icmp_seq=3 ttl=64 time=1.81 ms
64 bytes from 192.168.6.130: icmp_seq=4 ttl=64 time=0.077 ms
64 bytes from 192.168.6.130: icmp_seq=5 ttl=64 time=0.100 ms
64 bytes from 192.168.6.130: icmp_seq=6 ttl=64 time=0.175 ms
64 bytes from 192.168.6.130: icmp_seq=7 ttl=64 time=0.101 ms
64 bytes from 192.168.6.130: icmp_seq=8 ttl=64 time=0.272 ms
64 bytes from 192.168.6.130: icmp_seq=9 ttl=64 time=0.178 ms
64 bytes from 192.168.6.130: icmp_seq=10 ttl=64 time=0.104 ms
--- 192.168.6.130 ping statistics ---
10 packets transmitted, 10 received, 0% packet loss, time 9216ms
rtt min/avg/max/mdev = 0.077/0.359/1.809/0.508 ms
# !/bin/bash
echo script has begin
ping -c 10 192.168.6.130
cat testscript.sh
echo script has been ended......
script has been ended......
Conclusion:
We have reached the end of this article. In this guide, we have walked you through the steps required to create a Shell and Subshell on Rocky Linux 9.2. Your feedback is much welcome.
Comments ( 0 )
No comments available