shell script example
Shell Scripts

Basic Shell Script Examples In Linux

Shell script examples in linux covers some of the basics of shell scripts.This example contains basic commands on linux.

If you are looking for basic shell scripts then this article is for you.

Shell Script For Showing Two Numbers Entered By User:

In this example we have define two variables.This two variable will take two vales from user.The “echo” command used for display the output.The $ sign fetch values from variable when we use it on echo command.

read a
read b
echo $a
echo $b

Shell Script For Addition Of Two Values Entered By User

In this example a and b are two variables.The x variable used for storing the addition.We use backcode “`” to execute a mathmetical expression.

echo Enter Two Numbers
read a
read b
echo The Numbers You Have Added: $a,$b
x=`expr $a + $b`
echo The Sum Is : $x

Shell Script For Checking Two Numbers Are Equal Or Not:

read a
read b
if{[$a -eq $b]
    echo They Are Equal
    echo They Are Not Equal

You can also use this script to find the gretest value in two numbers.

read a
read b
read c
if[$a -gt $b -a $a -gt $c]
    echo A is greater
elif [$b -gt $a -a $b -gt $c]
     echo B Is Greater
    echo C Is Greater

Printing Numbers For A Particular Range

echo Enter Two Ranges
read m
read n
while [$i -le $n]
   echo $i
   let i=i+1

Division Of Two Numbers:

echo "Enter Two Numbers"
read a
read b
t=`expr $a / $b`
echo "The Division Is"
echo $t

Find Factorial Of A Number:

echo "Enter A number"
read n
while [$n -ge 1]
fact=`expr $fact\ $n`
n=`expr $n-1`
echo "The Factorial Is $Fact"

This are some of the basic examples.For more shell script examples bookmark us.For more contents like our facebook page.

This Linux command may also useful

25 Basic Linux Commands For Beginners

Sharing is caring!

Leave a Reply

Your email address will not be published. Required fields are marked *