Showing posts with label if else statement. Show all posts
Showing posts with label if else statement. Show all posts

13 January 2012

Shell Script to find Greatest of Three Number using if-else Statement

30 comments

Q. How do I write Shell Script to find Greatest of Three Numbers by If-else statement


Ans:

#!/bin/bash
echo "enter first number"
read first
echo "enter second number"
read sec
echo "enter third number"
read third
if [ $first -gt $sec ] ; then
if [ $first -gt $third ] ; then
echo -e " $first is greatest number "
else
echo -e " $third is greatest number "
fi
else
if [ $sec -gt $third ] ; then
echo -e " $sec is greatest number "
else
echo -e " $third is greatest number "
fi
fi
Read More...