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