Saturday, October 6, 2012

How to find the biggest among 3 given numbers in Unix


##################################################################
# To find the biggest among 3 given numbers                                          #
##################################################################

#!/bin/ksh/

# To make sure sufficient arguments
if [ $# -ne 3 ]
then
echo "Please provide the three arguments"
exit -1
fi

# Declaring and assigning values to the local variables
A=$1
B=$2
C=$3

#Logical part to find the largest number among 3 numbers
if [ $A -gt $B  -a  $A -gt $C ]
   then
   echo "A $A is the biggest number"
        elif  [ $B -gt $A  -a  $B -gt $C ]
        then
        echo "B $B is the biggest number"
                elif  [ $C -gt $A -a  $C -gt $B ]
                then
                echo "C $C is the biggest number"

   elif  [ $A -eq $B -a $A -eq $C -a $B -eq $C -a  $C -eq $B ]
   then
  echo "All numbers are same"
fi

exit 0