I had a problem with chmod not working. It seemed to be related to something in my path. I spent more time on this script to test removing individual path components than I would have done brute forcing it. And it didn't tell me the problem, as it was related to at least two path entries.
However, this script does demonstrate something or other about working with arrays in Bash. Mostly it demonstrates how awkward the exercise is.