Complex and bash script should not be in the same sentence. If a script you have is becoming complex, that’s an hint to use an anemable programming language with proper data types and structures.
Shell scripts is for automating shell sessions.