Script works with bash 3.0 but not 3.2.

Hello,

So my knowledge of bash scripting is not that great and I have been trying to solve this problem on my own for awhile to no avail.

Here's the error I get when running it with an OS that uses bash 3.2.x:

testagain.sh: line 10: -1: syntax error: operand expected (error token is "-1")

Here's the script (sorry for the lack of indents not sure how the formatting on this forum works):

#!/bin/bash

cd /home/sites

for logdir in */logs; do
        
        for access_log in ${logdir}/access_log.*; do
              
                lognum=`echo $access_log | sed -e 's/.*access_log\.//'`;
                lognum=$(($lognum-1));
                mv $access_log ${logdir}/access_log-$(date -d"- $lognum  days" '+%Y%m%d');

        done

done

It appears that the following line is returning an unexpected value

lognum=`echo $access_log | sed -e 's/.*access_log\.//'`;

You can check by adding a "echo $lognum" statement

Problem solved, had to add something to the script to make sure directories were not empty. Thanks again for your help!