diff mbox series

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

Message ID 20201015055827.29410-2-rosenp@gmail.com
State New
Headers show
Series [PATCHv2,1/4] base-files/functions.sh: read grep output by line | expand

Commit Message

Rosen Penev Oct. 15, 2020, 5:58 a.m. UTC
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@gmail.com>
 v2: replaced break with continue
 package/base-files/files/lib/functions.sh | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
diff mbox series


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"