shell实现统计期内时间加1循环

##end=`date +%Y%m%d`
end=20130302
start='20121229'
echo "start:"$start",end:"$end
while [ $end -gt $start ] 
do
#newstart=`expr substr $start 1 4`-`expr substr $start 5 2`-`expr substr $start 7 2`
year=`expr substr $start 1 4`
month=`expr substr $start 5 2`
day=`expr substr $start 7 2`
echo $year-$month-$day
case $month in
            1|01|3|03|5|05|7|07|8|08|10|12) maxday=31;;
            4|04|6|06|9|09|11) maxday=30;;
            2|02)
                if [ `expr $year % 4` -eq 0 ]; then
                        if [ `expr $year % 400` -eq 0 ]; then
                                maxday=29
                        elif [ `expr $year % 100` -eq 0 ]; then
                                maxday=28
                        else
                                maxday=29
                        fi
                else
                        maxday=28
                fi;;
esac
if [ $day -eq $maxday ];then
       if [ $month -eq 12 ];then
           month=01
           day=01
           year=`expr $year + 1`
       elif [ $month -lt 12 ];then
        month=`expr $month + 1`
if [ $month -lt 10 ] ;then
month=0$month
fi
        day=01
       fi
else
day=`expr $day + 1`
if [ $day -lt 10 ] ;then
day=0$day
fi
fi
start=$year$month$day
done

你可能感兴趣的:(shell)