(1)整数运算
expr 10 + 20
expr $num1 + $num2 + - * / %
[root@localhost scripts]# expr 10 + 20
30
[root@localhost scripts]# num1=10
[root@localhost scripts]# num2=20
[root@localhost scripts]# expr $num1 + $num2
30
[root@localhost scripts]# sum=$(expr $num1 + $num2)
[root@localhost scripts]# echo $sum
30
echo $(($num1+$num2)) + - * / %
echo $((5-3))
sum=$((1+2));echo $sum
echo $[2+2]
echo $[$num1+$num2]
num=$[$num1+$num2];echo $num
let num=2+3;echo $num
let i++;echo $i
#!/bin/bash
mem_user=$(free -m | grep "^Mem" | awk '{print $3}')
mem_total=$(free -m | grep "^Mem" | awk '{print $2}')
let mem_percent=$mem_user*100/$mem_total
echo "现在内存使用率是$mem_percent%"
(2) 小数运算
echo "2*4"|bc
echo "2^4"|bc
echo "scale=2;6/4"|bc 保留小数两位
awk 'BEGIN{print 1/2}'
echo "scale=2;6.0/4"|bc