I am currently planning on writing a bigger shell script. The script itself consists of many smaller scripts. I want to organize it modular. For example:
.
├── mainScript.sh
└── modules
├── moduleScript_1.sh
├── moduleScript_2.sh
└── moduleScript_3.sh
1 directory, 4 files
The mainScript will import the modules and defines some shared variables. The single modules are designed to be also useable on their own, so that I can run a module from console if I only need it's certain function.
I know that I can "source" the files just like:
#! /bin/bash
sharedVariable="share"
source ./module/moduleScript_1.sh
source ./module/moduleScript_2.sh
source ./module/moduleScript_3.sh
...but I am worried about scopes and interfering variables or functions.
Is this file structure actually a good practice, or is there a better, more advanced, way to handle bigger scripts with multiple modules?
Thanks in advance!