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 is an example script initializes two variables with numeric values. Then perform an addition operation on both values and store results in the third variable.

In this second example, shell script reads two numbers as command line parameters and perform the addition operation.


$ ./sum.sh 12 14       # Executing script

Sum is: 26

Here is another example of a shell script, which takes input from the user at run time. Then calculate the sum of given numbers and store to a variable and show the results.


Enter first number: 12
Enter second number: 15
Sum is: 27
Tags , , ,
Was this article helpful to you? Yes 37 No 14