bash脚本从数组中的列表中检查已安装的字体,并检查循环执行命令



更新为工作代码

我正在尝试逐一检查${fontArray}中列出的已安装字体,并将未找到的字体添加到新阵列${missingFonts}中,以便稍后在我的环境中的每台机器上运行更长的"构建后健康检查"时打印。

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

返回

| FAIL | Fonts      = Missing Fonts: font1 font2 font3

提前感谢你帮助一只老狗学习新技巧!

感谢@DavidC.Rankin的协助!

为什么不

if ! system_profiler SPFontsDataType | grep -q "Full Name: $i"; 
then missingFonts+=("$i"); 
fi 

添加丢失的字体?不用担心去掉前缀sed,除非你需要。这应该会建立你丢失的字体列表

最新更新