Shell Script to Add Two Integers
Brief: This example will help you to understand to add two numbers in the bash script. This script takes the input of two numbers from the user and prints the sum of both numbers.
This sample script initializes two variables with numeric values. Then add two number variables and store in another variable.
The below shell script uses read command to prompt the user for two numbers. Then calculate the sum of given numbers and store to another variable.
read -p "Enter first number: " num1
read -p "Enter second number: " num2
echo "Sum is: $sum"
Enter first number: 12 Enter second number: 14 Sum is: 26