let "m = 4 * 1024"; echo $m
Read full article from How to Add Calculations to a Bash Script
let "m = a % 100"
let "m += 15"
let "m++"
let "m--"
let "k = (m < 9) ? 0 : 1"
Floating Point Arithmetic in Bash
The let operator only works for integer arithmetic. For floating point arithmetic you can use for example the GNU bc calculator:
echo "32.0 + 1.4" | bc
Backticks (back single quotes) can be used to evaluate an arithmetic expression as in this example:
echo `expr $m + 18`
m=`expr $m + 18`
Another way to evaluate arithmetic expressions is to use double parenthesis:
(( m *= 4 ))
No comments:
Post a Comment