diff mbox series

[PATCHv2,1/4] base-files/functions.sh: read grep output by line

Message ID 20201015055827.29410-1-rosenp@gmail.com
State Deferred
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/SC2013

For loops by default (subject to $IFS) read word by word.
Additionally, glob expansion will occur.

I believe the intended use case of these loops is to read lines.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
 package/base-files/files/lib/functions.sh | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/package/base-files/files/lib/functions.sh b/package/base-files/files/lib/functions.sh
index 7da0c872fa..59bb0fe711 100755
--- a/package/base-files/files/lib/functions.sh
+++ b/package/base-files/files/lib/functions.sh
@@ -182,7 +182,8 @@  default_prerm() {
 	fi
 
 	local shell="$(command -v bash)"
-	for i in $(grep -s "^/etc/init.d/" "$root/usr/lib/opkg/info/${pkgname}.list"); do
+	grep -s "^/etc/init.d/" "$root/usr/lib/opkg/info/${pkgname}.list" | while IFS= read -r i
+	do
 		if [ -n "$root" ]; then
 			${shell:-/bin/sh} "$root/etc/rc.common" "$root$i" disable
 		else
@@ -260,7 +261,8 @@  default_postinst() {
 
 		if grep -m1 -q -s "^/etc/uci-defaults/" "$filelist"; then
 			[ -d /tmp/.uci ] || mkdir -p /tmp/.uci
-			for i in $(grep -s "^/etc/uci-defaults/" "$filelist"); do
+			grep -s "^/etc/uci-defaults/" "$filelist" | while IFS= read -r i
+			do
 				( [ -f "$i" ] && cd "$(dirname $i)" && . "$i" ) && rm -f "$i"
 			done
 			uci commit
@@ -270,7 +272,8 @@  default_postinst() {
 	fi
 
 	local shell="$(command -v bash)"
-	for i in $(grep -s "^/etc/init.d/" "$root$filelist"); do
+	grep -s "^/etc/init.d/" "$root$filelist" | while IFS= read -r i
+	do
 		if [ -n "$root" ]; then
 			${shell:-/bin/sh} "$root/etc/rc.common" "$root$i" enable
 		else