且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

乘上命令行终端UNIX

更新时间:2023-11-03 23:17:28

是的,你可以使用的 bash中内置的算术展开 $(()) 做一些简单的数学

Yes, you can use bash's built-in Arithmetic Expansion $(( )) to do some simple maths

$ echo "$((5 * 5))"
25

检查Shell在Bash参考手册运算部分运营商的完整列表。

Check the Shell Arithmetic section in the Bash Reference Manual for a complete list of operators.

有关完整起见,其他指出的那样,如果你需要任意precision, BC DC 效果会更好。

For sake of completeness, as other pointed out, if you need arbitrary precision, bc or dc would be better.