diff mbox

[kvm-unit-tests] Make scripts/arch-run.bash compatible with Bash 4.1 and older

Message ID 20180418215955.100008-1-pshier@google.com (mailing list archive)
State New, archived
Headers show

Commit Message

Peter Shier April 18, 2018, 9:59 p.m. UTC
KVM unit tests scripts/arch-run.bash uses test -v to check whether a variable
was set. The -v switch was introduced in Bash 4.2. This patch uses the older
test -z to test for an empty string.

test -v was used on a variable that is set on the prior line so it would never
be empty or considered unset. This patch moves the test earlier to check whether
there is a SHA in the errata file.

This patch also adds double quotes around source strings for read commands. On
older Bash versions, without the quotes the read will parse the string into its
components but then place them all into a single variable separated by spaces
rather than into separate variables as the script intends.

Tested: Ran with an injected empty string in errata.txt to verify with
git://git.kernel.org/pub/scm/virt/kvm/kvm-unit-tests.git at
073ea627a4268333e0e2245382ecf5fabc28f594.

Signed-off-by: Peter Shier <pshier@google.com>
---
 scripts/arch-run.bash | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
diff mbox

Patch

diff --git a/scripts/arch-run.bash b/scripts/arch-run.bash
index e13af8e8064a..f0a9b1d7c53c 100644
--- a/scripts/arch-run.bash
+++ b/scripts/arch-run.bash
@@ -234,8 +234,8 @@  env_generate_errata ()
 	local kernel_version kernel_patchlevel kernel_sublevel kernel_extraversion
 	local line commit minver errata rest v p s x have
 
-	IFS=. read -r kernel_version kernel_patchlevel rest <<<$kernel_version_string
-	IFS=- read -r kernel_sublevel kernel_extraversion <<<$rest
+	IFS=. read -r kernel_version kernel_patchlevel rest <<<"$kernel_version_string"
+	IFS=- read -r kernel_sublevel kernel_extraversion <<<"$rest"
 	kernel_sublevel=${kernel_sublevel%%[!0-9]*}
 	kernel_extraversion=${kernel_extraversion%%[!0-9]*}
 
@@ -249,8 +249,8 @@  env_generate_errata ()
 		commit=${line%:*}
 		minver=${line#*:}
 
+		test -z "$commit" && continue
 		errata="ERRATA_$commit"
-		test -v $errata && continue
 
 		IFS=. read -r v p rest <<<"$minver"
 		IFS=- read -r s x <<<"$rest"