I'm using solaris 5.10 and bash. I want to zip file "Amount.txt" to "Amount.zip" and rename it to "Amount_<prev_month>_<this year>.zip". For example, file for this month should be renamed to "Amount_06_2012.zip", for next month it should be "Amount_07_2012.zip". I have no problem for zipping the file. Here's the script but it's not working:
month=`date +%m`
year=`date +%Y`
lmonth=`expr $month - 1`
if test "$lmonth" = "0"
then
lmonth=12
year=`expr $year - 1`
fi
mv Amount.zip Amount_`$lmonth`_`$year`.zip
When I executed it, it shows:
./script.sh: 6: not found
./script.sh: 2012: not found
---------- Post updated 07-17-12 at 11:03 AM ---------- Previous update was 07-16-12 at 05:03 PM ----------
By the way, if i want to display month as "Jun" not "6", i have to use:
month=`date +%h`
instead of
month=`date +%m`
But if i use the new parameter, I cannot directly substract the month to get the previous month. Is there way to solve this so I can use "Jun" not "6"?