UNIT - IV
SHELL
PROGRAMMING
What is shell?
Shell is an interface in linux architecure that interact
with kernal directly and also interact through
applications with user indirectly.
Shell is a program used to interpret and manage
commands
FUNCTIONS OF SHELL
The shell provides a way to run programs, work with
the file system, compile computer code,and manage
the computer.
What is shell script?
Normally shells are interactive.
It means shell accept command from you (via keyboard) and
execute them.
But if you use command one by one (sequence of 'n' number of
commands),then you can store this sequence of command to text
file and tell the shell to execute this text file instead of
entering the commands. This is know as shell script
YOU CAN SAY
shell script/shell procedure/shell program
Some definations of shell script:
Shell script is executable text file that contains linux or unix
commands.
Shell script is a program typed by user and executed by shell and
kernel.
Shell script is the method of executing commands which are stored
in file.
when a group of command have to be executed regurly,they
should be stored in file,and the file itself is executed as a shell
script or shell program
Shell Script is series of command written in plain text file.
How to Create shell script/shell procedure/shell program?
We can create shell script using follwing steps.
[Link] terminal
[Link] vi with shell script name and “.sh”
extension.
Syntax: $ vi [Link]
[Link] terminal ,type following command to create
and open shell script.
$ vi [Link] and press ENTER
3. The shell script will open with each line starting
with tilde character and last line showing script
filename as "[Link]" [New File]. The cursor will be
blinking in first line at start.
When shell script opened to create in [Link] looks like following figure .
[Link] type command we should go to insert mode of vi editor, hence
press “i”.
[Link] your commands of shell script.
[Link] completion of typing command press ESCAPE to go out from
insert mode.
7. To save script and close vi editor type,
:x and press enter
[Link] close vi without saving script type,
:q and press enter
[Link] execute shell script,go to command mode of vi and type shell
script name with “sh” command.
syntax to execute shell script
$ sh [Link] and press enter
Ex. $ sh [Link] and press enter
If u want to edit shell script,again open shell script,then make [Link] and
close script by :x and execute script.
Why to Write Shell Script ?
● Shell script can take input from user, file and
output them on screen.
● Useful to create our own commands.
● Save lots of time.
● To automate some task of day to day life.
● System Administration part can be also
automated