[PATCHv2 1/4] base-files/functions.sh: read grep output by line
Rosen Penev
rosenp at gmail.com
Thu Oct 15 01:58:24 EDT 2020
>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 at gmail.com>
---
package/base-files/files/lib/functions.sh | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
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
--
2.17.1
More information about the openwrt-devel
mailing list