2006-8-9 10:10
快乐小猪
用| 或〈 这种流方式存在的问题,中间究竟发生了什么
三个对比脚本脚本: 只有最后个for循环才是正确的,为什么呢?请高手指教一二.
用| 或〈 这种流方式存在的问题,中间究竟发生了什么,为什么两个while循环都无法往外传递最后的$sum:lu3:
==============================
#!/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
==================================
2006-8-11 15:27
aicoa
第二个跟第三个应该是可以的,第一个是有问题
因为"cat vmstat.log |while read id"这个形式只把vmstat.log的内容传给了"while read id"这个句子,而不是while-do-done的循环,相当于成了这样
"while read id < vmstat.log"
btw,这个是为了统计cpu空闲的和吗?好象没有意义哎
2006-8-26 10:25
炸鸡
第二个肯定不行,光while read id这句是没意义的。id里面的值是什么?
2006-9-7 19:49
beginner-bj
问题出在vmstat.log
页:
[1]
Powered by Discuz! Archiver 5.5.0
© 2001-2006 Comsenz Inc.