If you need to write bash scripts, you probably have to accept arguments, and so I can tell you there are some minefields that you will step on over time. Feel free to use my code, which was built in the shadow of many exploding landmines, and keep both your feet intact.
The github link talks about what it does and how. It doesn't really talk about why other solutions are unacceptable, and why I keep using it after all these years. For that, I just posted a recent blog post about the tool, that you may also find useful: