我想编写一个脚本来识别某人是否正在从我的samba服务器传输数据(即音乐正在播放或不播放)。对于这一点,我想出了一个这样的脚本:bash中的round变量没有打印到标准输出
$ cat /home/ron/scripts/keepup.sh
#!/bin/bash
exec=`nethogs -t -c 1| awk '/smbd/ {print $2}'`
sent=$exec
echo "result: "$sent
sent="($sent+0.5)/1" | bc
echo "rounded: "$sent
if [[ $sent -gt 0 ]]
then
echo "music is playing"
else
echo "quiet"
fi
,但我得到:
Waiting for first packet to arrive (see sourceforge.net bug 1019381)
result: 6.73438
rounded: 6.73438
/home/ron/scripts/keepup.sh: line 10: [[: 6.73438: syntax error: invalid arithmetic operator (error token is ".73438")
quiet
虽然它显然应该计算出结果“6.73438”为真。看起来我的四舍五入不正常。我搜索了一下,但只使用echo或printf找到了答案,但这是我需要的npt,因为我想将舍入结果提供给if条件。