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

#!/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"
Get the latest tutorials on SysAdmin, Linux/Unix, Open Source, and DevOps topics:
CategoryList of Unix and Linux commands
File Management cat
Firewall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilities dig host ip nmap
OpenVPN CentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Manager apk apt
Processes Management bg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searching grep whereis which
User Information groups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPN CentOS 8 Debian 10 Firewall Ubuntu 20.04
8 comments… add one
  • hamza May 24, 2012 @ 20:33

    i love it, cos am just learning shell

  • sameer mishra Apr 9, 2012 @ 1:51

    superb logic

  • mahendra bohra Mar 25, 2012 @ 12:20

    this is good because all steps are defined

  • Muthu Lakshmanan Oct 14, 2011 @ 16:43

    I Like thisssssssssssssssss

  • trilok Sep 27, 2011 @ 9:53

    thanx for help us….

  • sanjay kundu Nov 20, 2009 @ 10:25

    the program length is very simple

    • mayur Aug 11, 2010 @ 6:01

      really simple…

  • SABAREESAN Jul 3, 2008 @ 13:21

    thanks !!! helps 4 learning unix 4 begineers like me

Leave a Reply

Your email address will not be published. Required fields are marked *

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.