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 )) #8Print out the prime factors of a number (e.g. 50)
factor 50
# 50: 2 5 5Sum 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?