utils/config: fix shellcheck errors

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.

Signed-off-by: Arnout Vandecappelle <arnout@mind.be>
2023.02.x
Arnout Vandecappelle 2023-02-08 13:50:45 +01:00
parent dc364c6ae6
commit 7150edc790
1 changed files with 4 additions and 8 deletions

View File

@ -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
;;