Answers for "how to do math in bash"

1

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
Posted by: Guest on April-28-2021

Code answers related to "how to do math in bash"

Code answers related to "Shell/Bash"

Browse Popular Code Answers by Language