#read file
counter=0
cat $filename | while read LINE
do
LineText=$LINE
if [ $LineText -eq 0 ]
then
counter=$(($counter+1))
elif [ $counter -gt 0 ]
then
echo $counter
counter=0
fi
done
#test the last counter if>0 print
if [ $counter -gt 0 ]
then
echo $counter
fi
#read file
counter=0
while read LINE
do
LineText=$LINE
if [ $LineText -eq 0 ]
then
counter=$(($counter+1))
elif [ $counter -gt 0 ]
then
echo $counter
counter=0
fi
done < $filename
#test the last counter if>0 print
if [ $counter -gt 0 ]
then
echo $counter
fi
------解决方案--------------------
cat ------解决方案-------------------- while 这种方式会启动一个 sub shell ------解决方案--------------------