我正在研究一个 500 行的 shell 脚本,有什么想法可以将其分解为较小的模块或可在 main.sh 文件中调用的可重用 shell 脚本吗?我正在寻找代码的可维护性和可重用性,即 DRY。
当我尝试在 first.sh 和 second.sh 等中调用 break down main.sh 时。
在哪里
first.sh
FOO=fobar
function hello(){
echo "hellow
}
main.sh
echo "calling main script by including sub scripts"
first.sh
echo $FOO
hello
当我运行 ./main.sh 输出时,我无法访问我的变量和方法
line 20: hello: command not found