I wrote a util a bit like this when I realised there was no command for emptying a directory: https://github.com/adamserafini/emptydir
If you do stick with bash, I would recommend giving shellcheck a try. It won't catch everything, but I've learned a lot from running it on my code.