1. Home
  2. Bash
  3. Examples
  4. Add two numbers?

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.

Output:

Enter first number: 12
Enter second number: 14
Sum is: 26
Tags , , ,
Was this article helpful to you? Yes 6 No 5