You don't specify what is going wrong. What is your problem?

As extra suggestions I would recomment:
making the -bbb part more flexible than just those 8 bans. Build a script for matching the number of -b's with the number of bans in the address list. If it exeeds the max number of -b's then group these unban statements

There is no need to use set here, you are using %testban as a temporary var, so just use var.