In this example ( by refixed coder ), we will CALCULATE ADDITION, SUBTRACTION, MULTIPLICATION, AND DIVISION IN UNIX
[ refixed coder ]
Shell script for Arithmetic Operation
Code:
first_num=0
second_num=0
input_fun(){
echo -n "Enter first number: "
read first_num
echo -n "Enter second number: "
read second_num
}
checker=1
while [ $checker ]
do
echo "------------------------------"
echo "ARITHMETIC OPERATION"
echo "1. Addition"
echo "2. Subtraction"
echo "3. Multiplication"
echo "4. Division"
echo "5. To exit OPERATION"
echo "------------------------------"
echo -n "CHOOSE YOUR OPERATION: "
read choice
result=0
if [[ $choice -eq 1 ]]
then
input_fun
result=`echo $first_num + $second_num | bc`
echo "Result : " $result
elif [[ $choice -eq 2 ]]
then
input_fun
result=`echo $first_num - $second_num | bc`
echo "Result : " $result
elif [[ $choice -eq 3 ]]
then
input_fun
result=`echo $first_num \* $second_num | bc`
echo "Result : " $result
elif [[ $choice -eq 4 ]]
then
input_fun
result=`echo $first_num / $second_num | bc`
echo "Result : " $result
elif [[ $choice -eq 5 ]]
then
exit 1
else
echo "Wrong Input"
echo "Choose another Input"
fi
done
OUTPUT IMAGE:
JOIN OUR DISCORD SERVER
_______________________________
Invitation link -
_______________________________
0 Comments