Friday, January 13, 2012

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


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

0 comments:

Post a Comment