Shell script to read 3 numbers and find the greaters of the three
Posted in Shell Math
#!/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"
Download - Email this to a friend - Printable version
Discussion on This Shell Script:
Leave a Reply
We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Thank you very much for stopping by our site!
Tags: bash shell script, elif, eq, fi, greaters, if command, read command, shell conditional and ~ Last updated on: April 4, 2008


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