How to Create a Shell and Subshell on Oracle Linux 9.2
To Create A Shell And Subshell On Oracle Linux 9.2
Introduction
What is Shell?
A shell is a special program that acts as an interpreter between the user and the operating system. Shell accepts human-readable commands from a user and converts them into Kernel-readable language. It is a command language interpreter that executes commands read from input devices such as keyboards or from files. The shell gets started when the user logs in or starts the terminal.
What is Subshell?
Subshell is an important concept in shell scripting that allows you to execute commands within a separate shell environment. They can be created using the parentheses operator or the bash command, and they provide a way to isolate the effects of specific commands or operations.
Creation Steps:
Step 1: First Check the OS version by using the Following commands
[root@linuxhelp ~]# cat /etc/os-release
NAME="Oracle Linux Server"
VERSION="9.2"
ID="ol"
ID_LIKE="fedora"
VARIANT="Server"
VARIANT_ID="server"
VERSION_ID="9.2"
PLATFORM_ID="platform:el9"
PRETTY_NAME="Oracle Linux Server 9.2"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:oracle:linux:9:2:server"
HOME_URL="https://linux.oracle.com/"
BUG_REPORT_URL="https://github.com/oracle/oracle-linux"
ORACLE_BUGZILLA_PRODUCT="Oracle Linux 9"
ORACLE_BUGZILLA_PRODUCT_VERSION=9.2
ORACLE_SUPPORT_PRODUCT="Oracle Linux"
ORACLE_SUPPORT_PRODUCT_VERSION=9.2
Step 2: Next create a one script file by using Vim command
[root@linuxhelp ~]# vim script1
#!/bin/bash It is the first line should be present in every shell scripts. It’s called a shebang.
var=root
echo $var
echo $name
Step 3 : Using export command to assign the value for name variable.It is used to mark variables and functions to be passed to child processes.
[root@linuxhelp ~]# export name=linux
Step 4 : To execute the script first change the executable file permission by using the following command
[root@linuxhelp ~]# chmod +x script1
Step 5: To list the file by using the following commands
[root@linuxhelp ~]# ll
total 8
-rw-------. 1 root root 1062 Sep 4 17:37 anaconda-ks.cfg
drwxr-xr-x. 2 root root 6 Sep 6 20:10 Desktop
drwxr-xr-x. 2 root root 6 Sep 6 20:10 Documents
drwxr-xr-x. 2 root root 6 Sep 6 20:10 Downloads
drwxr-xr-x. 2 root root 6 Sep 6 20:10 Music
drwxr-xr-x. 2 root root 6 Sep 6 20:10 Pictures
drwxr-xr-x. 2 root root 6 Sep 6 20:10 Public
-rwxr-xr-x. 1 root root 45 Sep 6 20:23 script1
drwxr-xr-x. 2 root root 6 Sep 6 20:10 Templates
drwxr-xr-x. 2 root root 6 Sep 6 20:10 Videos
Step 6 : To execute the script by using the following command
[root@linuxhelp ~]# ./script1
root
linux
Step 7 :Next Copy the script1 file to script2 file by using the following command.
[root@linuxhelp ~]# cat script1 >> script2
Step 8: To list the file by using the following commands
[root@linuxhelp ~]# ll
total 12
-rw-------. 1 root root 1062 Sep 4 17:37 anaconda-ks.cfg
drwxr-xr-x. 2 root root 6 Sep 6 20:10 Desktop
drwxr-xr-x. 2 root root 6 Sep 6 20:10 Documents
drwxr-xr-x. 2 root root 6 Sep 6 20:10 Downloads
drwxr-xr-x. 2 root root 6 Sep 6 20:10 Music
drwxr-xr-x. 2 root root 6 Sep 6 20:10 Pictures
drwxr-xr-x. 2 root root 6 Sep 6 20:10 Public
-rwxr-xr-x. 1 root root 45 Sep 6 20:23 script1
-rw-r--r--. 1 root root 45 Sep 6 20:45 script2
drwxr-xr-x. 2 root root 6 Sep 6 20:10 Templates
drwxr-xr-x. 2 root root 6 Sep 6 20:10 Videos
Step 9 : Add some command in script 2 file by using Vim command
[root@linuxhelp ~]# vim script2
#!/bin/bash
var=root
echo $var
echo $name
pwd
ls
Step 10 : To execute the script first change the executable file permission by using the following command
[root@linuxhelp ~]# chmod +x script2
Step 11: To list the file by using the following commands
[root@linuxhelp ~]# ll
total 12
-rw-------. 1 root root 1062 Sep 4 17:37 anaconda-ks.cfg
drwxr-xr-x. 2 root root 6 Sep 6 20:10 Desktop
drwxr-xr-x. 2 root root 6 Sep 6 20:10 Documents
drwxr-xr-x. 2 root root 6 Sep 6 20:10 Downloads
drwxr-xr-x. 2 root root 6 Sep 6 20:10 Music
drwxr-xr-x. 2 root root 6 Sep 6 20:10 Pictures
drwxr-xr-x. 2 root root 6 Sep 6 20:10 Public
-rwxr-xr-x. 1 root root 45 Sep 6 20:23 script1
-rwxr-xr-x. 1 root root 61 Sep 6 20:46 script2
drwxr-xr-x. 2 root root 6 Sep 6 20:10 Templates
drwxr-xr-x. 2 root root 6 Sep 6 20:10 Videos
Step 12: To execute the script by using the following command
[root@linuxhelp ~]# ./script2
root
linux
/root
anaconda-ks.cfg Desktop Documents Downloads Music Pictures Public script1 script2 Templates Videos
Conclusion:
We have reached the end of this article. In this guide, we have walked you through the steps required to create user by using Shell Script on Oracle Linux 9.2. Your feedback is much welcome.
Comments ( 0 )
No comments available