1.expr命令
[root@foundation63 ~]# a=123
[root@foundation63 ~]# expr $a + 10
133
[root@foundation63 ~]# expr $a - 10
113
[root@foundation63 ~]# expr $a * 10 #此命令不能识别,必须加\
expr: syntax error
[root@foundation63 ~]# expr $a \* 10
1230
[root@foundation63 ~]# expr $a / 10
12
[root@foundation63 ~]# expr $a % 10
3
2.$[]
和$(())
表达式
[root@foundation63 ~]# a=10
[root@foundation63 ~]# echo $[a+10]
20
[root@foundation63 ~]# echo $[a-10]
0
[root@foundation63 ~]# echo $[a*10]
100
[root@foundation63 ~]# echo $[a/10]
1
[root@foundation63 ~]# echo $[a%10]
0
[root@foundation63 ~]# echo $((a+10))
20
[root@foundation63 ~]# echo $((a-10))
0
3.let命令(let命令在执行后会保存新的值)
[root@foundation63 ~]# let a+=10
[root@foundation63 ~]# echo $a
20
[root@foundation63 ~]# let a-=10
[root@foundation63 ~]# echo $a
10
[root@foundation63 ~]# let a*=10
[root@foundation63 ~]# echo $a
100
[root@foundation63 ~]# let a/=10
[root@foundation63 ~]# echo $a
10
[root@foundation63 ~]# let a%=10
[root@foundation63 ~]# echo $a
0
4.小数运算工具bc
[root@foundation63 ~]# echo "scale=4;1.23*4.56" | bc ##(scale=4,表示保留4位小数)
5.6088
[root@foundation63 ~]# echo "scale=2;1.23*4.56" | bc
5.60
[root@foundation63 ~]# echo 1.2+3.4 | bc
4.6
[root@foundation63 ~]# echo 1.23+4.56 | bc
5.79
计算两个数的加减乘除
#!/bin/bash
read -t 5 -p "请输入两个整数:" a b
echo "a+b=$[a+b]"
echo "a-b=$[a-b]"
echo "a*b=$[a*b]"
echo "a/b=$[a/b]"
echo "a**b=$[a**b]"
echo "a%b=$[a%b]"
运行结果