shell编程之数学运算

shell数学运算支持整数运算的四种方法

1.let命令

no1=4;

no2=5;

let result=no1+no2

2.[]操作符

result=$[ no1 + no2]

3.(())操作符

result=$((no1 + no2))

4.expr命令

result='expr 3 +4'

若要支持浮点型,需要通过管道的形式将运算表达式传给bc

echo "4 * 0.56" | bc

 

posted @ 2013-08-06 23:52  l851654152  阅读(185)  评论(0编辑  收藏  举报