Maybe it’s becuase i grew up on python and bash still seems somewhat alien to me, but any time I’m crafting something with more than three or so nested functions, I use python as a wrapper for bash. Python initiates a bash script, parses the retval, inititates the next bash script from that data, etc.
https://xkcd.com/619/
Relevant xkcd.