Hey everyone! I've been working on a Bash script that checks various Kubernetes tasks, and it has grown significantly with many functions and variables. Now, when I need to make edits, I'm often losing track of these functions and their relationships. Is there a good way to automatically generate a dependency graph for my Bash functions? Appreciate any advice!
5 Answers
It sounds like your script could benefit from better organization. I've worked on large Bash programs too, and as long as you structure it well, it can be as manageable as code in other languages. Maybe breaking your functions into modules could help?
If you aren't using one already, I highly recommend a proper IDE with Bash support, like VSCode with the Bash IDE extension. It would allow you to find references to your functions easily and navigate through your code smoothly. Adding tools like shellcheck can also make life a lot easier!
Honestly, Bash isn’t really meant for big projects. If your script is getting too big and complex, it might be time to consider switching to a language like Python that handles larger projects better with its classes and modules. Just a thought!
Totally get that, but switching languages now would take too much time for me. I'm on a tight schedule.
I feel you! I can't stand Python either with all its imports and version issues. When I see Python code, I want to translate it back to Bash since it often runs better!
Even a basic IDE like Geany can help with organizing your script and managing your functions better. It's worth checking out!
I've started grouping my functions and variables like C header files and call them shell libraries with a .sh-lib extension. This way, I can 'source' them easily in my scripts and manage dependencies better, like choosing between two libraries for different tools.
Yeah, I agree that the structure is lacking. What started as a simple guide has turned into a fully automated process, and now it's a bit messy.