According to the man grep page, the -c flag is for
-c, --count Suppress normal output; instead, print the number of matching lines for each input file.
So you see the hit counter and are not confused with the grep exit code. Code 1 caused by the absence of lines matching the input.
Look at another case
echo 'No' | grep -c No 1 echo $? 0
Also read on EXIT CODES on the man grep page,
OUTPUT STATE Normally, the output status is 0 if a line is selected, 1 if no lines are selected, and 2 if an error occurs.
Inian
source share