Script:
#!/bin/bash
vpct=5.3
echo $((vpct*15))
Error:
./abc.sh: line 5: 5.3: syntax error: invalid arithmetic operator (error token is ".3")
我知道我不需要脚本来进行乘法5.3 * 15
,但是这个小脚本可以挑出错误。请指教。
根据http://www.softpanorama.org/Scripting/Shellorama/arithmetic_expressions.shtml http://www.softpanorama.org/Scripting/Shellorama/arithmetic_expressions.shtml:
Bash 不理解浮点运算。它将包含小数点的数字视为字符串。
您应该使用 bc 来执行此类计算,就像在 Dogbane 的解决方案中一样,只不过您应该使用引号对表达式进行转义,以便*
字符不会导致不必要的 shell 扩展。
echo "$vpct*15" | bc
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)