如何在bash shell脚本中添加整数和浮点数 [英] How to add an integer number and a float number in a bash shell script

查看:202
本文介绍了如何在bash shell脚本中添加整数和浮点数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个数字:

value1=686
value2=228.35

我无法添加整数和浮点数.请帮我得到结果.

I am not able to add an integer and a float. Please help me out to get the result.

我正在bash中运行它.

I am running it in bash.

推荐答案

echo 1 + 3.5 | bc

awk "BEGIN {print 1+3.5; exit}"

python -c "print 1+3.5"

perl -e "print 1+3.5"

只需用您的变量替换数字,例如:echo $n1 + $n2 | bc

Just replace the numbers with your variables, eg: echo $n1 + $n2 | bc

这篇关于如何在bash shell脚本中添加整数和浮点数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆