To obtain the number of lines produced by the while loop, the wc word count can be used
cd /System/Library/Extensions
find *.kext -prune -type d | while read d; do
codesign -v "$d" 2>&1 | grep "invalid signature"
done | wc -l
wc -l the -l option counts the number of lines in the input, which is piped to the output of while
Now if you need to count the number of grep outputs in each iteration of the while loop, the -c option of grep would be usefull.
cd /System/Library/Extensions
find *.kext -prune -type d | while read d; do
codesign -v "$d" 2>&1 | grep -c "invalid signature"
done
-c Suppress normal output; instead print a count of matching lines
for each input file
codesign -v "$d" 2>&1or overall count of the while loop?