【发布时间】:2019-04-30 14:19:42
【问题描述】:
我正在尝试执行以下操作:
size=$(curl -sI "https://stackoverflow.com/posts/0/editor-heartbeat/ask" | grep -i Content-Length | awk '{print $2}')
echo $((size / 3))
但这会返回错误:
")syntax error: invalid arithmetic operator (error token is "
我猜这与awk的结果有关。
提前谢谢你。
【问题讨论】:
-
为什么不在管道末尾的
awk中进行算术运算? -
curl -sI "https://stackoverflow.com/posts/0/editor-heartbeat/ask" | awk '/Content-Length/{print $2/3; exit}' -
和
echo "size=${size}ZZZ"在您的计算之前确保只有数值保存到$size。祝你好运。