From patchwork Sun Sep 20 05:31:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rosen Penev X-Patchwork-Id: 1367786 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.openwrt.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BvGTC70QVz9sTC for ; Sun, 20 Sep 2020 15:33:51 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:List-Subscribe:List-Help:List-Post:List-Archive:List-Unsubscribe :List-Id:MIME-Version:Message-Id:Date:Subject:To:From:Reply-To:Cc:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Owner; bh=0dA9/ZquCijTSDvNNyK6hs0oTjvwBs86HqEsJWZLnAM=; b=lPdX6H0AgKT7GLxiH/0+RH4EGr 3HTd6zTnBpp2CQ/945u1pLfz3BO40kdPGVA/z1JW+5vvaaTFM4ksf+yx3grE5g365cSXA6qt+/obZ QM46alpo3t1jT5pm+7soxs9eZFX+tRVY5OtTDjreH2kaT3L8C+/Lx4oxauEf8qnUllaqkHvu5QPB5 EDIVdU8pTybLxgKvHMQjnsuq4dIfIvvs/2jPut7y9euyPXyahBfT9Z2FT2zEJheJ5REdcGGmw74Yd 7G2E8lmfJJ/E+dXO3jLkw/OhTWRDd2am7zXkvpQw5lOP9TH9g2uJDZr9yo+hjTADbsinUQykxhkFt ZXyQSmnA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kJrwz-0004Mw-Dd; Sun, 20 Sep 2020 05:31:49 +0000 Received: from mail-pl1-x643.google.com ([2607:f8b0:4864:20::643]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kJrww-0004Lf-FT for openwrt-devel@lists.openwrt.org; Sun, 20 Sep 2020 05:31:47 +0000 Received: by mail-pl1-x643.google.com with SMTP id e4so5189757pln.10 for ; Sat, 19 Sep 2020 22:31:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=GuIEbixRZklzysqpRTnT1gTu+Xh15bGomVt0pLxRF9k=; b=D6p/9whvCZoUbgtUjcrMRxGY/663KmA/mrR5wjf0bT6UYLtU/GQ5PksFQJP7AUgxDX 7zzBLBrKA8HuyafLLURibNaStNN/TkqOiosCfx/uWmYWP1wkly1LO3EtrHyib2owh5yn hxHarG+tTmgi8QuRunRLtbTua/8c8HpA9StpuxNB+hGzx41Kc3IGSVK/DJW1M21BZwdu sJzDa/GHaoz18gaYW9MMsCKdGxTtFkQV5LMofP1Jxt9rMSa+d6C1WnEeDMEzMPS8wHMJ w3EXswICXhz1Ip2NqgsC1K8NviYMpHDxG//bG5FfO1DHtxbi2HvixF5ZGtShTohcek45 syCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=GuIEbixRZklzysqpRTnT1gTu+Xh15bGomVt0pLxRF9k=; b=Cgbf8umgBC2PpdXWaksQmuHkGSjjFb+98mzacj3emaHA3YxuDuY22YNrYH+2DB/wGQ KvYtNGF3R8wPyBiPt0VggZBl/Ojig7NyBUwd21Rmn6KCoJr7U6J/w0DJP3Z9+mouLPV2 dgibR6CKeinv4Xkh/Dx+tzrcNj8BK/R/dNq0xaYD94gf63kd0UZ21n+42MBizis/4WdZ J+mZD2Z6zYJiewyx1y8Z2wntCF5368OSnbuUo1r5RCbxHG5SRYTKzCPhzj+UXWOiHEby oI0vq07cTyUvHp47XBXdmdqGtoh5HLeukg36qmB7aO5XUnyyA8Syn6tBL3BNnkpyHz2N KUmA== X-Gm-Message-State: AOAM533zh/R0StmBk2T0RJDWxEJ2VM0rdtK9VLxpt8s8gieinhSl97U/ cSvHTUJJwvkR6Vg8jTw2kmMcazCgUFBdgw== X-Google-Smtp-Source: ABdhPJx3+oPc26fWKcjKvHUyfPvh9oL6rbvcOLSDayGZgE/2eFKk6mJ8fztfyI+JpxfCKzDsUC0UQw== X-Received: by 2002:a17:902:e9d3:b029:d1:f370:1e90 with SMTP id 19-20020a170902e9d3b02900d1f3701e90mr17949281plk.76.1600579902294; Sat, 19 Sep 2020 22:31:42 -0700 (PDT) Received: from mangix-trapnet.lan ([2001:470:1f05:79e::a89]) by smtp.gmail.com with ESMTPSA id 25sm8052450pfj.35.2020.09.19.22.31.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Sep 2020 22:31:41 -0700 (PDT) From: Rosen Penev To: openwrt-devel@lists.openwrt.org Subject: [PATCH 1/4] base-files/functions.sh: read grep output by line Date: Sat, 19 Sep 2020 22:31:37 -0700 Message-Id: <20200920053140.35255-1-rosenp@gmail.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200920_013146_577842_EA9B00CE X-CRM114-Status: GOOD ( 12.35 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:643 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [rosenp[at]gmail.com] -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org 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 --- 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