Shell script : Year value is not returned

I am trying to get the year of the previous month.
The below code is returning blank year value (i.,e no year value is printed)

findPrvYear(){
(
set `date +%m" "%Y`
CURMTHY=$1
CURYRY=$2
if [ $CURMTHY -eq 01 ]
then PRVMTHY=12
     PRVYRY=$(expr $CURYRY - 1)
else PRVMTHY=$(expr $CURMTHY - 1)
     PRVYRY="$CURYRY"
fi
return "$PRVYRY"
)
}

thisMonthY=$(date +%m)
thisYearY=$(date +%y)
retPrvYear=$(findPrvYear $thisMonthY $thisYearY)
echo "valueassigned" $retPrvYear   //This is not printing year value


Source: unix

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.