三个对比脚本脚本: 只有最后个for循环才是正确的,为什么呢?请高手指教一二.
用| 或〈 这种流方式存在的问题,中间究竟发生了什么,为什么两个while循环都无法往外传递最后的$sum

==============================
#!/bin/sh
sum=0
vmstat 5 10 |awk '{print $22}' |tr -d 'id' >vmstat.log
cat vmstat.log |while read id
#for id in `cat vmstat.log`
do
if [ ! "$id" = "" ];then
sum=`expr $sum + $id`
else
return
fi
echo $id
done #<vmstat.log
echo "sum="$sum
==============================
#!/bin/sh
sum=0
vmstat 5 10 |awk '{print $22}' |tr -d 'id' >vmstat.log
while read id
#for id in `cat vmstat.log`
do
if [ ! "$id" = "" ];then
sum=`expr $sum + $id`
else
return
fi
echo $id
done <vmstat.log
echo "sum="$sum
================================
#!/bin/sh
sum=0
vmstat 5 10 |awk '{print $22}' |tr -d 'id' >vmstat.log
#cat vmstat.log |while read id
for id in `cat vmstat.log`
do
if [ ! "$id" = "" ];then
sum=`expr $sum + $id`
else
return
fi
echo $id
done #<vmstat.log
echo "sum="$sum
==================================