美文网首页
二、Shell脚本数学运算

二、Shell脚本数学运算

作者: 一个反派人物 | 来源:发表于2021-01-08 16:54 被阅读0次

1. expr

expr num1 运算符 num2 运算符...,expr、数字、运算符之间必须有空格
只能取整运算:
+
-
\*
/
% 取余

2. let

变量计算中不需要加上 $ 来表示变量,除基本运算外,还支持**幂运算

自加操作:let no++
自减操作:let no--
简写形式 let no+=10,let no-=20,分别等同于 let no=no+10,let no=no-20。

#!/bin/bash
let a=5+4 b=9-3
echo $a $b
9 6

3. bc可以计算小数

scale=N,可以设定bc支持的小数位数

echo "scale=2;10/3" | bc
3.33

相关文章

网友评论

      本文标题:二、Shell脚本数学运算

      本文链接:https://www.haomeiwen.com/subject/lexboktx.html