Math

Math

Arithmetic Expansion in Bash (Operators: +, -, *, /, %, etc)

echo $(( 10 + 5 ))  #15
x=1
echo $(( x++ )) #1 , notice that it is still 1, since it's post-incremen
echo $(( x++ )) #2
echo $(( ++x )) #4 , notice that it is not 3 since it's pre-incremen
echo $(( x-- )) #4
echo $(( x-- )) #3
echo $(( --x )) #1
x=2
y=3
echo $(( x ** y )) #8
factor 50
# 50: 2 5 5

Sum up input list (e.g. seq 10)

Sum up a file (each line in file contains only one number)

Column subtraction

Simple math with expr

More math with bc

Last updated

Was this helpful?