命令行终端上的乘法 [英] Multiplication on command line terminal
本文介绍了命令行终端上的乘法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用串行终端为我们的实验提供输入.我发现使用
I'm using a serial terminal to provide input into our lab experiment. I found that using
$ echo "5X5"
只返回字符串"5X5"
.有执行乘法运算的命令吗?
just returns a string of "5X5"
. Is there a command to execute a multiplication operation?
推荐答案
Yes, you can use bash's built-in Arithmetic Expansion $(( ))
to do some simple maths
$ echo "$((5 * 5))"
25
在Bash中检查 Shell算术部分参考手册了解操作员的完整列表.
Check the Shell Arithmetic section in the Bash Reference Manual for a complete list of operators.
为完整性起见,正如其他人指出的那样,如果需要任意精度,请 bc
或 dc
会更好.
For sake of completeness, as other pointed out, if you need arbitrary precision, bc
or dc
would be better.
这篇关于命令行终端上的乘法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文