Recursion is not evil; as long as you are aware of what happens internally when you call a function, and the pitfalls.
First, make sure tou have a stop condition that will execute when the recursive function completes its task. If you don't you don't have a recursive function, but an wndless loop.
Next, variables and re-entry points. Each call to a function pushes information on the stack; the address of the reentry point (address of the next instruction when the function returns). Then you have to reserve the space for tge return value type.
Next is a matter of scope. The variables passes as parameters, and the local variables declared in the function. Each time the function is called, this space has to be allocated on the stack, and is held there until popped out by returning to the calling function. So, eventually you will run out of stack memory (stack overflow condition).
I wrote a "Towers of Hanoi" program for a pascal class that was being taught on a DEC Vax. I tried to create a condition that would crash my program or VMS by being able to add as many poles and as many rings as I wanted. I got to 1000 rings on 3 poles, and the program still ran. It took about 10 minutes to run, but ir ran.
Anyway, back to your question. What seems to be going on here is your variables are in the wrong scope - it looks like they are being invoked in the global environment, not the local. So, any changes made in the variable by the function is reflected in all instances of the function. All changes need to be made in a local scope, and then the values returned to the calling function. I'm not sure if an interpitive language like bash supports local variables, and may make every variable visable to all the script's logic.
Hope this helps.