Shell Scripts

Basic Shell Script Examples

In this shell script examples you will learn 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]
then
    echo They Are Equal
else
    echo They Are Not Equal
fi

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]
then
    echo A is greater
elif [$b -gt $a -a $b -gt $c]
then
     echo B Is Greater
else
    echo C Is Greater

Printing Numbers For A Particular Range

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

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:

fact=1
echo "Enter A number"
read n
while [$n -ge 1]
do
fact=`expr $fact\ $n`
n=`expr $n-1`
done
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 *