IMP(shellcheck): replace ls in loop by glob (SC2045)

This commit is contained in:
Thibault Ayanides 2020-12-14 14:45:38 +01:00
parent fad8e8c1f1
commit 0c16e500f5
2 changed files with 16 additions and 12 deletions

View File

@ -29,12 +29,13 @@ audit() {
if [ "$SEARCH_RES" = 1 ]; then break; fi if [ "$SEARCH_RES" = 1 ]; then break; fi
if test -d "$FILE_SEARCHED"; then if test -d "$FILE_SEARCHED"; then
debug "$FILE_SEARCHED is a directory" debug "$FILE_SEARCHED is a directory"
for file_in_dir in $(ls "$FILE_SEARCHED"); do for file_in_dir in "$FILE_SEARCHED"/*; do
does_pattern_exist_in_file "$FILE_SEARCHED/$file_in_dir" "^$PATTERN" [[ -e "$file_in_dir" ]] || break # handle the case of no file in dir
does_pattern_exist_in_file "$file_in_dir" "^$PATTERN"
if [ "$FNRET" != 0 ]; then if [ "$FNRET" != 0 ]; then
debug "$PATTERN is not present in $FILE_SEARCHED/$file_in_dir" debug "$PATTERN is not present in $file_in_dir"
else else
ok "$PATTERN is present in $FILE_SEARCHED/$file_in_dir" ok "$PATTERN is present in $file_in_dir"
SEARCH_RES=1 SEARCH_RES=1
break break
fi fi
@ -61,12 +62,13 @@ apply() {
if [ "$SEARCH_RES" = 1 ]; then break; fi if [ "$SEARCH_RES" = 1 ]; then break; fi
if test -d "$FILE_SEARCHED"; then if test -d "$FILE_SEARCHED"; then
debug "$FILE_SEARCHED is a directory" debug "$FILE_SEARCHED is a directory"
for file_in_dir in $(ls "$FILE_SEARCHED"); do for file_in_dir in "$FILE_SEARCHED"/*; do
does_pattern_exist_in_file "$FILE_SEARCHED/$file_in_dir" "^$PATTERN" [[ -e "$file_in_dir" ]] || break # handle the case of no file in dir
does_pattern_exist_in_file "$file_in_dir" "^$PATTERN"
if [ "$FNRET" != 0 ]; then if [ "$FNRET" != 0 ]; then
debug "$PATTERN is not present in $FILE_SEARCHED/$file_in_dir" debug "$PATTERN is not present in $file_in_dir"
else else
ok "$PATTERN is present in $FILE_SEARCHED/$file_in_dir" ok "$PATTERN is present in $file_in_dir"
SEARCH_RES=1 SEARCH_RES=1
break break
fi fi

View File

@ -59,12 +59,14 @@ apply() {
if [ "$SEARCH_RES" = 1 ]; then break; fi if [ "$SEARCH_RES" = 1 ]; then break; fi
if test -d "$FILE_SEARCHED"; then if test -d "$FILE_SEARCHED"; then
debug "$FILE_SEARCHED is a directory" debug "$FILE_SEARCHED is a directory"
for file_in_dir in $(ls $FILE_SEARCHED); do
does_pattern_exist_in_file "$FILE_SEARCHED/$file_in_dir" "^$PATTERN" for file_in_dir in "$FILE_SEARCHED"/*; do
[[ -e "$file_in_dir" ]] || break # handle the case of no file in dir
does_pattern_exist_in_file "$file_in_dir" "^$PATTERN"
if [ "$FNRET" != 0 ]; then if [ "$FNRET" != 0 ]; then
debug "$PATTERN is not present in $FILE_SEARCHED/$file_in_dir" debug "$PATTERN is not present in $file_in_dir"
else else
ok "$PATTERN is present in $FILE_SEARCHED/$file_in_dir" ok "$PATTERN is present in $file_in_dir"
SEARCH_RES=1 SEARCH_RES=1
break break
fi fi