I'm writing a style-checking script that:
- looks for some abuse of style using grep
- prints a message and the offending lines IF they are found
- otherwise, prints nothing
I'm currently using
if (grep -Erq 'break;|continue' *) then
echo && echo "found breaks and/or continues:"
grep -Ern 'break;|continue' *
else echo "no breaks or continues found."
fi
Is there a way to store the result of the first grep (the one in the if conditional with the -q flag) to use later (between the echo statements), or do I have to do the search twice if I want to print out the intermediate echo messages? I understand there are simple workarounds to this particular problem; this is a smaller example of something I want to do at-scale.