The only good part of sh/bash script is to run commands with piping/redirection support IMO,other than that I saw posts like this to explain sh/bash script’s puzzles/pitfalls all the time.
Maybe it is time to consider using rust instead: https://github.com/rust-shell-script/rust_cmd_lib ?