Use find instead of ls to avoid splitting filenames that contain spaces.
Use rm -f instead of if ... then rm ...; fi. This patch addresses all
shellcheck complaints about the run_tests.sh shell script.

Signed-off-by: Bart Van Assche <bvanass...@acm.org>
---
 tools/lib/lockdep/run_tests.sh | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/tools/lib/lockdep/run_tests.sh b/tools/lib/lockdep/run_tests.sh
index eef3fe4a24fe..e4f41318aa79 100755
--- a/tools/lib/lockdep/run_tests.sh
+++ b/tools/lib/lockdep/run_tests.sh
@@ -6,7 +6,7 @@ if ! make >/dev/null; then
     echo "FAILED!"
 fi
 
-for i in `ls tests/*.c`; do
+find tests -name '*.c' | sort | while read -r i; do
        testname=$(basename "$i" .c)
        echo -ne "$testname... "
        if gcc -o "tests/$testname" -pthread "$i" liblockdep.a -Iinclude 
-D__USE_LIBLOCKDEP &&
@@ -15,12 +15,10 @@ for i in `ls tests/*.c`; do
        else
                echo "FAILED!"
        fi
-       if [ -f "tests/$testname" ]; then
-               rm tests/$testname
-       fi
+       rm -f "tests/$testname"
 done
 
-for i in `ls tests/*.c`; do
+find tests -name '*.c' | sort | while read -r i; do
        testname=$(basename "$i" .c)
        echo -ne "(PRELOAD) $testname... "
        if gcc -o "tests/$testname" -pthread -Iinclude "$i" &&
@@ -29,7 +27,5 @@ for i in `ls tests/*.c`; do
        else
                echo "FAILED!"
        fi
-       if [ -f "tests/$testname" ]; then
-               rm tests/$testname
-       fi
+       rm -f "tests/$testname"
 done
-- 
2.20.0.rc0.387.gc7a69e6b6c-goog

Reply via email to