如何在bash中使用浮点除法? [英] How do I use floating-point division in bash?

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

问题描述

我试图在Bash脚本中划分两个图像宽度,但是bash给了我 0 作为结果:

  RESULT = $(($ IMG_WIDTH / $ IMG2_WIDTH))

我没有学习Bash指南,我知道我应该使用 bc ,在互联网上的所有例子中都使用 bc 。在 echo 我试图把同样的东西放在我的 SCALE 中,但是它不起作用。



以下是我在教程中找到的示例:

  echoscale = 2; $ {userinput}| bc 

如何让Bash给我一个像 0.5的浮动

解决方案

你不能。只有bash 才是整数;你必须委托给一个工具,比如 bc


I am trying to divide two image widths in a Bash script, but bash gives me 0 as the result:

RESULT=$(($IMG_WIDTH/$IMG2_WIDTH))

I did study the Bash guide and I know I should use bc, in all examples in internet they use bc. In echo I tried to put the same thing in my SCALE but it didn't work.

Here is the example I found in the tutorials:

echo "scale=2; ${userinput}" | bc 

How can I get Bash to give me a float like 0.5?

解决方案

You can't. bash only does integers; you must delegate to a tool such as bc.

这篇关于如何在bash中使用浮点除法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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