Bash脚本算术语法错误 [英] Error in Bash script arithmetic syntax

查看:63
本文介绍了Bash脚本算术语法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

脚本:

#!/bin/bash
vpct=5.3 
echo $((vpct*15))    

错误:

./abc.sh: line 5: 5.3: syntax error: invalid arithmetic operator (error token is ".3")

我知道我不需要一个脚本来乘以 5.3 * 15 ,但是这个小脚本可以找出错误.请告知.

I know I don't need a script to multiply 5.3 * 15, but this small script to single out the error. Please advise.

推荐答案

除了 bc ,还有其他工具可以尝试

Besides bc, there are other tools you can tools you can try

awk -v vpct="$VPCT" 'BEGIN{print vpct * 15}'

echo $vpct | ruby -e 'print gets.to_f * 15 '

echo  "$vpct 15 * p" | dc

这篇关于Bash脚本算术语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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