bash do math with variables code example
Example: how to do math in bash
# Basic syntax:
# Subtraction
expr 1 - 1
0
# Addition
expr 1 + 1
2
# Assign result to a variable
myvar=$(expr 1 + 1)
echo $myvar
2
# Addition with a variable
expr $myvar + 1
3
# Division
expr $myvar / 3
0
# Multiplication
expr $myvar \* 3
6