How can we do Shell Scripting

A shell script is a file that contains commands that shell can execute. he commands in the shell script can be any commands you can enter in response to a shell prompt.

Let me explain you how to do shell scripting with some examples :

First of all create a new file with extension .sh . Let us name it as . This script work as a calculator to find addition, subtration , multilication, division, of 2 numbers.
Apply these commands on terminal to create it.

$ cd Desktop
$ touch
$ vim

Now go to Insert mode in vim editor by ressing ‘i’ and edit the file so that it look as follows :

read a b
echo a= add
echo b= sub
echo c= mul
echo d= div
echo ch
read ch
case $ch in
let z= $a + $b
echo add= $z
let z= $a - $b
echo sub=$z
let z= $a * $b
echo mul= $z
let z= $a / $b
echo div= $z
echo invalid option

Then save this file by pressing ‘Esc’ and then ‘:wq!’. THis save your file and let you come out of vim editor to command line.
Next you need to run the script.
For this if the permission of file does not allow you to execute the programe then apply the command :

$ chmod 755 -R

And then run the script by command :

$ ./

This will prompt you to enter 2 numbers and then what operation you want to apply on it. Your choice will be then executed to form your solution.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s