I always thought the quiet (
-q) option had to be used when using
grep conditionally. But re-reading the
man page it seems like it should work without it.
So if you want to print matches and use it in a conditional, can you just do something like
grep PATTERN FILE && do_something_else
The only thing that makes me uncertain is that there appears to be a slight difference in exit status.
- grep will "exit immediately with zero status if any match is found, even if an error was detected".
- "The exit status is 0 if selected lines are found, and 1 if not found. If an error occurred the exit status is 2".
But I can't think of an example where the difference will become noticeable?