[PATCHv2 2/4] base-files/functions.sh: do not iterate over ls

Rosen Penev rosenp at gmail.com
Thu Oct 15 01:58:25 EDT 2020


>From https://github.com/koalaman/shellcheck/wiki/SC2045

When looping over a set of files, it's always better to use globs when
possible. Using command expansion causes word splitting and glob
expansion, which will cause problems for certain filenames (typically
first seen when trying to process a file with spaces in the name).

Signed-off-by: Rosen Penev <rosenp at gmail.com>
---
 v2: replaced break with continue
 package/base-files/files/lib/functions.sh | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/package/base-files/files/lib/functions.sh b/package/base-files/files/lib/functions.sh
index 59bb0fe711..61aa87b2dd 100755
--- a/package/base-files/files/lib/functions.sh
+++ b/package/base-files/files/lib/functions.sh
@@ -290,8 +290,9 @@ default_postinst() {
 include() {
 	local file
 
-	for file in $(ls $1/*.sh 2>/dev/null); do
-		. $file
+	for file in "$1"/*.sh; do
+		[ -e "$file" ] || continue
+		. "$file"
 	done
 }
 
-- 
2.17.1




More information about the openwrt-devel mailing list