Shell script to read 3 numbers and find the greaters of the three

in Categories Shell Math last updated April 4, 2008
#!/bin/bash
# Shell script to read 3 numbers and find the greaters of the three
# -------------------------------------------------------------------------
# Copyright (c) 2005 nixCraft project <http://cyberciti.biz/fb/>
# This script is licensed under GNU GPL version 2.0 or above
# -------------------------------------------------------------------------
# This script is part of nixCraft shell script collection (NSSC)
# Visit http://bash.cyberciti.biz/ for more information.
# ----------------------------------------------------------------------
echo -n "Please enter three numbers (separate number by space) : "
read a b c
# compare a with b and c. Note -a is logical and operator
if [ $a -gt $b -a $a -gt $c ]
then
   big=$a
elif  [ $b -gt $a -a $b -gt $c ] # compare b with a and c
then
   big=$b
elif  [ $c -gt $a -a $c -gt $b ] # compare c with a and b
then
   big=$c
elif [ $a -eq $b -a $a -eq $c -a $b -eq $c -a $c -eq $b ] # see if all of them are equal or not
then
   big="All three numbers are same (equal)"
else # something must be wrong if we are here, like one of number is character such as 'A'
   big="Can not guess greaters of three numbers"
fi
# display result 
echo "Result : $big"