0% found this document useful (0 votes)
5 views2 pages

ShellProgramming

Uploaded by

PrashansaBhatia
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

ShellProgramming

Uploaded by

PrashansaBhatia
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Ex. No. 2.

UNIX Shell Programming

A) MAXIMUM OF THREE NUMBERS:

Aim:
To write a shell program to find greatest of three numbers.

Algorithm:
Step1: Declare the three variables.
Step2: Check if A is greater than B and C.
Step3: If so, then print A is greater.
Step4: Else check if B is greater than C.
Step5: If so print B is greater.
Step6: Else print C is greater.
Program:
echo "enter A"
read a
echo "enter B"
read b
echo "enter C"
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"
fi

RUN:

Sample I/P:

Enter A:50
Enter B:35
Enter C:55

Sample O/P:
C is greater

Result: Thus the shell program to find the maximum of three numbers is executed and
the output is verified successfully.

9
B) FIBONACCI SERIES:

Aim:
To write a shell program to generate Fibonacci series.

Algorithm :
Step 1 : Initialise a to 0 and b to 1.
Step 2 : Print the values of 'a' and 'b'.
Step 3 : Add the values of 'a' and 'b'. Store the added value in variable 'c'.
Step 4 : Print the value of 'c'.
Step 5 : Initialise 'a' to 'b' and 'b' to 'c'.
Step 6 : Repeat the steps 3,4,5 till the value of 'a' is less than given number.

Program :
echo “enter the number”
read n
a=0
b=1
i=0
while [ $i – le $n ]
do
c=`expr $a + $b`
echo $c
a=$b
b=$c
i=`expr $i + 1‟
done

Sample I/P :
Enter the no: 5

Sample O/P:
011235

Result :
Thus the shell program to find the fibonacci series is executed and output is verified
successfully.

10

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy