FOO BAR FOO$ tail -f file | grep -m2 FOO
prints FOO twice but never returns. Whereas
$ tail -f file | grep -m2 -e FOO -e BAR
will exit.
This is because (from the grep(1) manual):
grep ensures that the standard input is positioned to just just after the last matching line before exiting, regardless of the presence of trailing context lines.
This bit me as I was trying to scan xscreensaver-command -watch for an unblanking event. However, because no events followed the UNBLANK immediately, grep didn't return and my script would not continue. I therefore rely on the LOCK event that (hopefully) preceeds the UNBLANK. It's not a big deal if this fails; I'll have to unlock my ssh-agent manually...