【发布时间】:2014-04-28 14:09:37
【问题描述】:
我正在尝试一些非常简单的方法,但我尝试的所有代码都不起作用。 我需要在 bash 中添加两个浮点数。我正在这样做:
result1=`$CURL -o /dev/null -s -w %{time_total} $url1`
result2=`$CURL -o /dev/null -s -w %{time_total} $url2`
result3=`$CURL -o /dev/null -s -w %{time_total} $url3`
total= `expr $result2 + $result3`
echo $total | $GAWK -F: '{ print "connection_1.value " $1 }'
但是在提示中我得到了这个输出:
./http_response_2: line 12: 0,018+0,255: command not found
connection_1.value
我也在尝试这样做:
result1=`$CURL -o /dev/null -s -w %{time_total} $url1`
result2=`$CURL -o /dev/null -s -w %{time_total} $url2`
result3=`$CURL -o /dev/null -s -w %{time_total} $url3`
total= `$result2 + $result3 | bc`
得到相同的结果。 提前致谢!
【问题讨论】:
-
去掉
total=和``expr...`之间的空格 -
将最后一个 sn-p 中的最后一行替换为:
total=$(bc <<< "$result2+$result3") -
@fedorqui 谢谢,但我得到了这个:expr: no integer argument
-
另外,
0,018+0,255中有逗号,而不是小数点。如果不是错字,那么应该是total=$(tr ',' '.' <<< "$result2 + $result3" | bc -l) -
^^ 这可以帮助你:stackoverflow.com/questions/8402181/…