From 332ac3b8cafe8c8ad613f85fccdcb1e72e6e0efc Mon Sep 17 00:00:00 2001 From: Michael Diamond Date: Thu, 23 Apr 2020 12:00:01 -0700 Subject: [PATCH] Updated SC2126 (markdown) --- SC2126.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SC2126.md b/SC2126.md index 731aa33..a0a910a 100644 --- a/SC2126.md +++ b/SC2126.md @@ -1,4 +1,4 @@ -## Consider using grep -c instead of grep|wc. +## Consider using `grep -c` instead of `grep | wc` ### Problematic code: @@ -38,7 +38,7 @@ if grep -q pattern file; then fi ``` -Also note that in `foo | grep bar | wc -l`, wc will mask the exit code of grep by default (i.e. without `set -o pipefail`), and always return success. If replacing with `foo | grep -c bar`, grep will exit non-zero when the count is 0. This is convenient for conditional statements but may require handling when used with `set -e`. +Also note that in `foo | grep bar | wc -l`, `wc` will mask the exit code of `grep` by default (i.e. without `set -o pipefail`), and always return success. If replacing with `foo | grep -c bar`, `grep` will exit non-zero when there are no matches. This is generally desirable (see above), but may require handling when used with `set -e`. ### Exceptions