Sum Of Two Numbers in Shell/Bash Programming

 



Sum Of Two Numbers


  • Explanation
  • Input

read Num1

read Num2

  • Sum

Sum=$(($Num1 + $Num2))  OR  Sum=`expr $Num1 + $Num2`

  • Output

echo "Sum Of Two Numbers=$Sum"


  • Example Code

#!/bin/bash
#Sum of two number without expr

echo "Enter the first Number"
read num1

echo "Enter the second Number"
read num2
sum=$(($num1 + $num2))
echo "Sum Of Two Number : $sum"


  • Result

Input : 

10 20

Output : 

Sum Of Two Number : 30


  • Note
For Any Query Comment in box given Below.
    Sum Of Two Numbers in Shell/Bash Programming Sum Of Two Numbers in Shell/Bash Programming Reviewed by CodexRitik on November 15, 2020 Rating: 5

    No comments:

    Powered by Blogger.