linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Kent Gibson <warthog618@gmail.com>
To: linux-gpio@vger.kernel.org, brgl@bgdev.pl
Cc: Kent Gibson <warthog618@gmail.com>
Subject: [libgpiod][PATCH 2/8] tools: tests: don't declare and assign separately
Date: Fri, 31 May 2024 21:45:06 +0800	[thread overview]
Message-ID: <20240531134512.443850-3-warthog618@gmail.com> (raw)
In-Reply-To: <20240531134512.443850-1-warthog618@gmail.com>

Fix shellcheck SC2155[1] - declare and assign separately to avoid
masking return values.

Signed-off-by: Kent Gibson <warthog618@gmail.com>

[1] https://www.shellcheck.net/wiki/SC2155
---
 tools/gpio-tools-test.bash | 28 +++++++++++++++++-----------
 1 file changed, 17 insertions(+), 11 deletions(-)

diff --git a/tools/gpio-tools-test.bash b/tools/gpio-tools-test.bash
index 34ea744..6bbb06c 100755
--- a/tools/gpio-tools-test.bash
+++ b/tools/gpio-tools-test.bash
@@ -49,7 +49,8 @@ output_is() {
 
 num_lines_is() {
 	[ "$1" -eq "0" ] || [ -z "$output" ] && return 0
-	local NUM_LINES=$(echo "$output" | wc -l)
+	local NUM_LINES
+	NUM_LINES=$(echo "$output" | wc -l)
 	assertEquals " number of lines:" "$1" "$NUM_LINES"
 }
 
@@ -73,16 +74,18 @@ gpiosim_chip() {
 
 	for ARG in "$@"
 	do
-		local KEY=$(echo $ARG | cut -d"=" -f1)
-		local VAL=$(echo $ARG | cut -d"=" -f2)
+		local KEY VAL
+		KEY=$(echo "$ARG" | cut -d"=" -f1)
+		VAL=$(echo "$ARG" | cut -d"=" -f2)
 
 		if [ "$KEY" = "num_lines" ]
 		then
 			echo $VAL > $BANKPATH/num_lines
 		elif [ "$KEY" = "line_name" ]
 		then
-			local OFFSET=$(echo $VAL | cut -d":" -f1)
-			local LINENAME=$(echo $VAL | cut -d":" -f2)
+			local OFFSET LINENAME
+			OFFSET=$(echo "$VAL" | cut -d":" -f1)
+			LINENAME=$(echo "$VAL" | cut -d":" -f2)
 			local LINEPATH=$BANKPATH/line$OFFSET
 
 			mkdir -p $LINEPATH
@@ -92,10 +95,11 @@ gpiosim_chip() {
 
 	echo 1 > $DEVPATH/live
 
-	local chip_name=$(<$BANKPATH/chip_name)
-	GPIOSIM_CHIP_NAME[$1]=$chip_name
-	GPIOSIM_CHIP_PATH[$1]="/dev/$chip_name"
-	GPIOSIM_DEV_NAME[$1]=$(<$DEVPATH/dev_name)
+	local CHIP_NAME
+	CHIP_NAME=$(<"$BANKPATH/chip_name")
+	GPIOSIM_CHIP_NAME[$1]=$CHIP_NAME
+	GPIOSIM_CHIP_PATH[$1]="/dev/$CHIP_NAME"
+	GPIOSIM_DEV_NAME[$1]=$(<"$DEVPATH/dev_name")
 }
 
 gpiosim_chip_number() {
@@ -3044,14 +3048,16 @@ die() {
 # Must be done after we sources shunit2 as we need SHUNIT_VERSION to be set.
 oneTimeSetUp() {
 	test "$SHUNIT_VERSION" = "$MIN_SHUNIT_VERSION" && return 0
-	local FIRST=$(printf "$SHUNIT_VERSION\n$MIN_SHUNIT_VERSION\n" | sort -Vr | head -1)
+	local FIRST
+	FIRST=$(printf "$SHUNIT_VERSION\n$MIN_SHUNIT_VERSION\n" | sort -Vr | head -1)
 	test "$FIRST" = "$MIN_SHUNIT_VERSION" && \
 		die "minimum shunit version required is $MIN_SHUNIT_VERSION (current version is $SHUNIT_VERSION"
 }
 
 check_kernel() {
 	local REQUIRED=$1
-	local CURRENT=$(uname -r)
+	local CURRENT
+	CURRENT=$(uname -r)
 
 	SORTED=$(printf "$REQUIRED\n$CURRENT" | sort -V | head -n 1)
 
-- 
2.39.2


  parent reply	other threads:[~2024-05-31 13:45 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-31 13:45 [libgpiod][PATCH 0/8] tools: tests: fix shellcheck warnings Kent Gibson
2024-05-31 13:45 ` [libgpiod][PATCH 1/8] tools: tests: don't mix string and array Kent Gibson
2024-05-31 13:45 ` Kent Gibson [this message]
2024-06-03  8:52   ` [libgpiod][PATCH 2/8] tools: tests: don't declare and assign separately Bartosz Golaszewski
2024-06-03  8:58     ` Kent Gibson
2024-06-03 10:38       ` Bartosz Golaszewski
2024-06-03 10:39         ` Kent Gibson
2024-05-31 13:45 ` [libgpiod][PATCH 3/8] tools: tests: fix unused variables Kent Gibson
2024-05-31 13:45 ` [libgpiod][PATCH 4/8] tools: tests: use read -r to avoid mangling backslashes Kent Gibson
2024-05-31 13:45 ` [libgpiod][PATCH 5/8] tools: tests: don't use variables in printf format string Kent Gibson
2024-05-31 13:45 ` [libgpiod][PATCH 6/8] tools: tests: check exit code directly Kent Gibson
2024-05-31 13:45 ` [libgpiod][PATCH 7/8] tools: tests: shellcheck don't follow sourced file Kent Gibson
2024-05-31 13:45 ` [libgpiod][PATCH 8/8] tools: tests: avoid splitting and globbing Kent Gibson
2024-06-03 10:40 ` [libgpiod][PATCH 0/8] tools: tests: fix shellcheck warnings Bartosz Golaszewski
2024-06-03 10:43   ` Kent Gibson
2024-06-03 10:59     ` Kent Gibson
2024-06-03 11:51       ` Bartosz Golaszewski
2024-06-03 14:59       ` Konstantin Ryabitsev

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240531134512.443850-3-warthog618@gmail.com \
    --to=warthog618@gmail.com \
    --cc=brgl@bgdev.pl \
    --cc=linux-gpio@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).