Introduction of Shell Scripting

SHELL SCRIPTING

INTRODUCTION OF SHELL

WHAT IS SHELL? A shell is a special program which acts as an interpreter between the user and the operating system. Shell accept human readable commands from a user and convert them into Kernel readable language. It is a command language interpreter that execute commands read from input devices such as keyboards or from files. The shell gets started when the user logs in or start the terminal.

Types Of Shell

There are Several types of shell are available. Some are

1.) Bourne shell The Bourne shell, called "sh," is one of the original shells, developed for Unix computers. some of the categories of bourne shells are listed below • Korn shell (ksh) • Bourne Again shell (bash)  It is the default shell on many Linux distributions • POSIX shell (sh)

2.) C shell

It was developed for a developer who has written C and C++ in Linux operating system.

some of the categories of C shells are listed below • C shell (csh) • TENEX/TOPS C shell (tcsh)

WHAT IS SHELL SCRIPT?

     Shell Script is a file which contains a series of Linux commands, Those commands are executed by the shell. It can combine lengthy and repetitive sequences of commands into a single and simple script, which can be stored and executed anytime. This reduces the efforts of the common user.

SHELL COMMANDS

ls, cd, cat, mkdir, cp, mv, for, while doing, etc…

SHABANG

#!/bin/bash

It is the first line should be present in every shell scripts. It’s called a shebang.

It represents the type of shell which we use to execute the script.

Example

List OF BASH SCRIPTS

[root@linuxhelp11 Desktop]# ll
total 12
-rwxr-xr-x 1 root root 24 Jul  1 19:31 bash.sh
-rwxr-xr-x 1 root root 22 Jul  1 19:51 csh.sh
-rwxr-xr-x 1 root root 22 Jul  1 19:33 zsh.sh

Content in each script

[root@linuxhelp11 Desktop]# cat bash.sh
#!/bin/bash
sleep 120
[root@linuxhelp11 Desktop]# cat csh.sh
#!/bin/csh
sleep 120
[root@linuxhelp11 Desktop]# cat zsh.sh
#!/bin/zsh
sleep 120

Execute script and check for SHELL using ps command

[root@linuxhelp11 Desktop]# ./bash.sh &
[7] 6158
[root@linuxhelp11 Desktop]# ps -fp 6158
UID         PID   PPID  C STIME TTY          TIME CMD
root       6158   5729  0 19:58 pts/1    00:00:00 /bin/bash ./bash.sh
[6]   Done                    ./bash.sh
[root@linuxhelp11 Desktop]#
[root@linuxhelp11 Desktop]# ./csh.sh &
[8] 6169
[root@linuxhelp11 Desktop]#
[root@linuxhelp11 Desktop]# ps -fp 6169
UID         PID   PPID  C STIME TTY          TIME CMD
root       6169   5729  0 19:58 pts/1    00:00:00 /bin/csh ./csh.sh

With this, the Introduction to Shell comes to an end.

FAQ
Q
Is Python a shell script?
A
Python has a very easy to read and understand syntax. Its style emphasizes minimalism and clean code while allowing the developer to write in a bare-bones style that suits shell scripting. Python is an interpreted language, meaning there is no compile stage.
Q
How to Execute script and check for SHELL?
A
Run the following commnad:
# ./bash.sh &
Q
What is the use of shell scripting?
A
It's called a shell script because it combines into a "script" in a single file a sequence of commands that would otherwise have to be presented to the system from a keyboard one at a time. The shell is the operating system's command interpreter and the set of commands you use to communicate with the system.
Q
what is shell scripting?
A
A shell is a special program which acts as an interpreter between the user and the operating system. Shell accept human readable commands from a user and convert them into Kernel readable language. It is a command language interpreter that execute commands read from input devices such as keyboards or from files. The shell gets started when the user logs in or start the terminal.
Q
What is shell Scripting?
A
A shell is a special program which acts as an interpreter between the user and the operating system. Shell accept human readable commands from a user and convert them into Kernel readable language. It is a command language interpreter that execute commands read from input devices such as keyboards or from files.