Updated SC2126 (markdown)

Michael Diamond
2020-04-23 12:00:01 -07:00
parent 98cb2ca30e
commit 332ac3b8ca

@@ -1,4 +1,4 @@
## Consider using grep -c instead of grep|wc. ## Consider using `grep -c` instead of `grep | wc`
### Problematic code: ### Problematic code:
@@ -38,7 +38,7 @@ if grep -q pattern file; then
fi 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 ### Exceptions