我有以下代码
for ip in $(ifconfig | awk -F ":" '/inet addr/{split($2,a," ");print a[1]}')
do
bytesin=0; bytesout=0;
while read line
do
if [[ $(echo ${line} | awk '{print $1}') == ${ip} ]]
then
increment=$(echo ${line} | awk '{print $4}')
bytesout=$((${bytesout} + ${increment}))
else
increment=$(echo ${line} | awk '{print $4}')
bytesin=$((${bytesin} + ${increment}))
fi
done < <(pmacct -s | grep ${ip})
echo "${ip} ${bytesin} ${bytesout}" >> /tmp/bwacct.txt
done
我想将增加的值打印到 bwacct.txt,但文件中充满了零:
91.227.223.66 0 0
91.227.221.126 0 0
127.0.0.1 0 0
我对 Bash 的理解是重定向的 for 循环应该保留变量。我究竟做错了什么?