Help with Backup Shell Script

i need to print the first date of the previous month in 20130101 format.

i use the below script

month_year=$(date +'%m%Y' | awk '!--$1{$1=12;$2--}')
m=${month_year% *}
y=$month_year##* }
d=$(cal $m $y | paste -s - | awk '{print $NF}')
firstdate=${printf '02d01%s' $y $m)
echo $firstdate

it print as "2013101"

any one can help me on this to print 20130101 as yyyymmdd format

---------- Post updated at 08:57 AM ---------- Previous update was at 08:56 AM ----------

thanks in advance

---------- Post updated at 09:36 AM ---------- Previous update was at 08:57 AM ----------

i m using

month_year=$(date +'%m%Y' | awk '!--$1{$1=12;$2--}')
m=${month_year% *}
y=$month_year##* }
d=$(cal $m $y | paste -s - | awk '{print $NF}')
firstdate=${printf '%s01%02d' $y $m)
echo $firstdate

the output is as 20130101

i m getting the correct o/p
thanks

In this way I get the first day in the previous month:

date +"%Y %m"| awk '{ printf "%4d%02d01\n", ($2 == 1)?$1-1:$1,($2 == 1)?12:$2 - 1;}'