tests: Fix shellcheck issue SC2126 by using 'grep -c'
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 0cec99d..e28e1bf 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -241,11 +241,10 @@
# SC2009: Consider using pgrep instead of grepping ps output.
# Sc2010: Don't use ls | grep. Use a glob or a for loop with a condition to allow non-alphanumeric filenames.
# SC2115: Use "${var:?}" to ensure this never expands to /*.
-# SC2126: Consider using grep -c instead of grep | wc
# SC2143: Use grep -q instead of comparing output with [ -n .. ].
# SC2148: Tips depend on target shell and yours is unknown. Add a shebang or a 'shell' directive.
# SC2181: Check exit code directly with e.g. if mycmd;, not indirectly with $?.
- shellcheck -e SC2001,SC2009,SC2010,SC2115,SC2126,SC2143,SC2148,SC2181 \
+ shellcheck -e SC2001,SC2009,SC2010,SC2115,SC2143,SC2148,SC2181 \
$(TESTS) $(TEST_UTILS) $(filter _test_%,$(EXTRA_DIST))
check: check-am check-display
diff --git a/tests/test_common b/tests/test_common
index 2ea0861..247cc9c 100644
--- a/tests/test_common
+++ b/tests/test_common
@@ -30,7 +30,7 @@
"^ [[:print:]]+$" \
; do
shift
- ctr=$(grep -E "${pattern}" "$logfile" | wc -l)
+ ctr=$(grep -c -E "${pattern}" "$logfile")
if [ "$ctr" -eq 0 ]; then
echo "Counted $ctr occurrences of pattern '${pattern}' in logfile; expected at least 1"
exit 1
@@ -48,7 +48,7 @@
"^[[:print:]]+$" \
; do
shift
- ctr=$(grep -E "${pattern}" "$logfile" | wc -l)
+ ctr=$(grep -c -E "${pattern}" "$logfile")
if [ "$ctr" -lt "$minocc" ]; then
echo "Counted $ctr occurrences of pattern '${pattern}' in logfile; expected at least $minocc"
exit 1
diff --git a/tests/test_tpm2_save_load_state_3 b/tests/test_tpm2_save_load_state_3
index 637f902..f0d357b 100755
--- a/tests/test_tpm2_save_load_state_3
+++ b/tests/test_tpm2_save_load_state_3
@@ -164,8 +164,7 @@
fi
# we want one line with xdigits and spaces
- res=$(grep -E "^[ [:xdigit:]]+$" < "$TMPFILE" |
- wc -l)
+ res=$(grep -c -E "^[ [:xdigit:]]+$" < "$TMPFILE")
if [ "$res" -ne 1 ]; then
echo "Error: nvread did not show expected results"
cat "$TMPFILE"