Skip to contentSkip to conversation

utils/config: fix shellcheck errors

Buildroot Arnout Vandecappelle 1 participant 1 message Feb 21, 2023

lore
Share & tools
lore
#0 lore raw

commit: https://git.buildroot.net/buildroot/commit/?id=7150edc790cda61270eb0ec1af7ab78255c90003
branch: https://git.buildroot.net/buildroot/commit/?id=refs/heads/next

In utils/config line 54:

                ARG="`echo $ARG | tr a-z- A-Z_`"
                     ^------------------------^ SC2006: Use $(...) notation instead of legacy backticked `...`.
                           ^--^ SC2086: Double quote to prevent globbing and word splitting.

Did you mean:

                ARG="$(echo "$ARG" | tr a-z- A-Z_)"

In utils/config line 87:
local tmpfile="$infile.swp"
^-----^ SC2034: tmpfile appears unused. Verify use (or export if used externally).

In utils/config line 182:
if [ $? != 0 ] ; then
^-- SC2181: Check exit code directly with e.g. 'if mycmd;', not indirectly with $?.

For more information:
https://www.shellcheck.net/wiki/SC2034 -- tmpfile appears unused. Verify us...
https://www.shellcheck.net/wiki/SC2086 -- Double quote to prevent globbing ...
https://www.shellcheck.net/wiki/SC2006 -- Use $(...) notation instead of le...

The suggestions from shellcheck can be applied.

The unused variable tmpfile in fact occurs in several functions, all of them can be removed.

For the check exit code, the condition is swapped to avoid negative logic.

---
 utils/config | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)
utils/config +4 -8
index c5e2d723ea..5f5e4362e5 100755
@@ -51,7 +51,7 @@ checkarg() {
 		usage
 	fi
 	if [ "$MUNGE_CASE" = "yes" ] ; then
-		ARG="`echo $ARG | tr a-z- A-Z_`"
+		ARG="$(echo "$ARG" | tr a-z- A-Z_)"
 	fi
 	case "$ARG" in
 	${BR2_PREFIX}*)
@@ -64,7 +64,6 @@ txt_append() {
 	local anchor="$1"
 	local insert="$2"
 	local infile="$3"
-	local tmpfile="$infile.swp"
 
 	# sed append cmd: 'a\' + newline + text + newline
 	cmd="$(printf "a\\%b$insert" "\n")"
@@ -76,7 +75,6 @@ txt_subst() {
 	local before="$1"
 	local after="$2"
 	local infile="$3"
-	local tmpfile="$infile.swp"
 
 	sed -i -e "s:$before:$after:" "$infile"
 }
@@ -84,7 +82,6 @@ txt_subst() {
 txt_delete() {
 	local text="$1"
 	local infile="$2"
-	local tmpfile="$infile.swp"
 
 	sed -i -e "/$text/d" "$infile"
 }
@@ -178,15 +175,14 @@ while [ "$1" != "" ] ; do
 		if grep -q "# ${BR2_PREFIX}$ARG is not set" $FN ; then
 			echo n
 		else
-			V="$(grep "^${BR2_PREFIX}$ARG=" $FN)"
-			if [ $? != 0 ] ; then
-				echo undef
-			else
+			if V="$(grep "^${BR2_PREFIX}$ARG=" $FN)"; then
 				V="${V/#${BR2_PREFIX}$ARG=/}"
 				V="${V/#\"/}"
 				V="${V/%\"/}"
 				V="${V//\\\"/\"}"
 				echo "${V}"
+			else
+				echo undef
 			fi
 		fi
 		;;

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot