Please understand that this answer is not a fish, it's a fishing lesson.
Start by debugging this with some print statements to see that the array iteration even attempts to use the values you think it's using. As in try printing i
are all the i's even looked at? What about the test statement, does test even pass? (and why bother checking if the row exists? just escape the error?)
Then if that's not the problem move one level deeper and so forth.
If we don't do this there are dozens of other possibilities that could be causing the problem.
At this point you should probably realize that the problem had nothing to do with mkdir, years, months, aix or anything other than your bash syntax.
Good luck!