Professional Documents
Culture Documents
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.
1 #!/bin/bash
2 # Calculate the sum of two integers with pre initialize values
3 # in a shell script
4
5 a=10
6 b=20
7
8 sum=$(( $a + $b ))
9
10 echo $sum
Output:
Sum is: 26
1 #/bin/bash
2 # Take input from user and calculate sum.
3 read -p "Enter first number: " num1
4 read -p "Enter second number: " num2
5 sum=$(( $num1 + $num2 ))
6 echo "Sum is: $sum"
7
8
9
Output:
Sum is: 27