bash 脚本从数组列表中检查已安装的字体并循环执行命令
bash script checking for installed fonts from list in an array and for loop to do commands
更新了工作代码
我正在尝试一个一个地检查 ${fontArray} 中列出的已安装字体,并将未找到的任何字体添加到新数组 ${missingFonts} 中,我可以稍后将其作为更长的一部分打印 "post-build health check" 运行 在我环境中的每台机器上。
Var19="Fonts"
fontArray=("font1" "font2" "font3")
missingFonts=()
for i in "${fontArray[@]}"; do
system_profiler SPFontsDataType | grep "Full Name: $i" | sed 's/.*: //'
if ! system_profiler SPFontsDataType | grep -q "Full Name: $i"; then
missingFonts+=("$i");
fi
done
if [ ${#missingFonts[@]} -eq 0 ]; then
Val9="Fonts Installed"
Check19=PASS
else
Val19="Missing Fonts: ${missingFonts[@]}"
Check19=FAIL
fi
Line19=" | ${Check19} | ${Var19} = ${Val19} "
echo "$Line19"
exit 0
哪个returns
| FAIL | Fonts = Missing Fonts: font1 font2 font3
在此先感谢您帮助一只老狗学习新技巧!
感谢的协助!
Why not then
if ! system_profiler SPFontsDataType | grep -q "Full Name: $i";
then missingFonts+=("$i");
fi
to add the missing fonts? Don't worry about stripping the prefix with
sed unless you need to. That should build your missing font list
更新了工作代码
我正在尝试一个一个地检查 ${fontArray} 中列出的已安装字体,并将未找到的任何字体添加到新数组 ${missingFonts} 中,我可以稍后将其作为更长的一部分打印 "post-build health check" 运行 在我环境中的每台机器上。
Var19="Fonts"
fontArray=("font1" "font2" "font3")
missingFonts=()
for i in "${fontArray[@]}"; do
system_profiler SPFontsDataType | grep "Full Name: $i" | sed 's/.*: //'
if ! system_profiler SPFontsDataType | grep -q "Full Name: $i"; then
missingFonts+=("$i");
fi
done
if [ ${#missingFonts[@]} -eq 0 ]; then
Val9="Fonts Installed"
Check19=PASS
else
Val19="Missing Fonts: ${missingFonts[@]}"
Check19=FAIL
fi
Line19=" | ${Check19} | ${Var19} = ${Val19} "
echo "$Line19"
exit 0
哪个returns
| FAIL | Fonts = Missing Fonts: font1 font2 font3
在此先感谢您帮助一只老狗学习新技巧!
感谢
Why not then
if ! system_profiler SPFontsDataType | grep -q "Full Name: $i"; then missingFonts+=("$i"); fi
to add the missing fonts? Don't worry about stripping the prefix with sed unless you need to. That should build your missing font list