Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

3
  • 11
    This should be the accepted answer, since it only suppresses the warning exit code (1) if grep does not find anything, yet it passes on true errors (exit codes > 1). The other solutions here always suppress true errors, which is usually bad. Commented Aug 29, 2019 at 21:26
  • 4
    This is great, but suffers from one issue - if the echo command exits with 1, the whole line will exit with 0, not just the grep. It might be worth checking this answer: unix.stackexchange.com/a/581991/58450. Commented Sep 22, 2020 at 23:17
  • if using bash, status of echo can be checked via ${PIPESTATUS[0]} Commented Sep 23, 2020 at 3:54