Updated with working code
I am trying to check for installed fonts listed in ${fontArray} one by one and add any that are not found to a new array ${missingFonts} that I can print later as part of a much longer "post-build health check" run on each machine in my environment.
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
which returns
| FAIL | Fonts = Missing Fonts: font1 font2 font3
Thanks in advance for helping an old dog learn new tricks!
Thanks @DavidC.Rankin for the assist!
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.