# 定义函数,根据路径执行install.sh脚本 run_install() { now_path=$(pwd) dir="$1" # 获取install.sh所在的目录名 sh_name=$2 echo "$dir" "$sh_name" cd "$dir" || exit # 进入该目录 # ./install.sh # 执行install.sh脚本 pwd cd "$now_path" || exit # 回到上一级目录 } # 逐行读取文件内容,根据=后面的值执行相应操作 while read line do var=$(echo "$line" | cut -d ':' -f 2) # 提取=后面的值 if [ "$var" = "ON" ] then key=$(echo "$line" | cut -d ':' -f 1) # 提取=前面的键 sh_name=$(echo "$line" | cut -d ':' -f 3) # 提取=前面的键 if [ -d "$key" ] then run_install "$key" "$sh_name" # 根据路径执行install.sh脚本 else echo "dir not exist:$key" fi elif [ "$var" != "" ] then echo "Unknow status: $var" fi done < config.txt