Saturday, February 27, 2016

Bash Script for Given 3 int values, a b c, return their sum

Bash Script for Given 3 int values, a b c, return their sum. However, if one of the values is the same as another of the values, it does not count towards the sum.  If all the three Numbers are same the answer should be Zero


#!/bin/bash
echo "Please enter first number"
read first
echo "Please enter second number"
read second
echo "Please enter Third Number"
read third
d=` expr $first + $second + $third`
e=` expr $second + $third`
f=` expr $first + $third`
g=` expr $first + $second`
if [ $first -eq $second  ] && [ $second -eq $third ]
then
        echo " All the Numbers are equal, The Sum is 0"
elif [ $first -eq $second ] && [ $second -ne $third ]
then
echo "*********************************************************************"
echo "Note : First  Number and Second Number are same, The addition is " $e
echo "*********************************************************************"
elif [ $first -ne $second ] && [ $second -eq $third ]
then
echo "*********************************************************************"
echo "Note : Second and third Number is same, The Sum is " $f
echo "*********************************************************************"
elif [ $first -ne $second ] && [ $second -ne $third ]
then
echo "*********************************************************************"
echo "None of the numbers are equal, The sum is " $d
echo "*********************************************************************"
elif [ $third -eq $first ] && [ $first -ne $second ]
then
echo "*********************************************************************"
echo "Note : Third and First Numbers are the same, The addition is" $g
echo "*********************************************************************"
fi








# End of Program

premkumar.waghmare@gmail.com