bash script for selecting grib files with cdo

hi, i am new with scripts and have a little problem.

i have a file with dates in the form YYYYMMDD, in average about 40 days per year.
now i shall cut those days with cdo selday from monthly files.
the script shall look up the days, forward them to the cdo operator and write the new grib files with the last day (sometimes there are some consecutive days).
this is my script so far:

rrdata=`cat rrstark_alldays.dat`

for i in $YYYYMMDD; do
        echo $i
done
for file in 'ls *.grb'; do
        cdo selday, DD, gp500_era40_europeYYYYMM.grb > gp500_$i_rrstrong.grb
done

has anybody exprience with such a problem?
thx a lot, judith

I think the top loop is supposed to be around the second loop:

for i in $YYYYMMDD; do
        echo $i

    for file in 'ls *.grb'; do
        cdo selday, DD, gp500_era40_europeYYYYMM.grb > gp500_$i_rrstrong.grb
    done
done

assuming I understood your problem.