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 test -n to to achieve equivalent functionality that is backward compatible. Add 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. Add check for missing commit in errata file. Tested: Ran with an injected empty commit field in errata.txt to verify with git://git.kernel.org/pub/scm/virt/kvm/kvm-unit-tests.git at 073ea627a4268333e0e2245382ecf5fabc28f594. Ran full test suite on Bash 4.1 Signed-off-by: Peter Shier <pshier@xxxxxxxxxx> --- scripts/arch-run.bash | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/scripts/arch-run.bash b/scripts/arch-run.bash index e13af8e8064a..7410cf4b87cd 100644 --- a/scripts/arch-run.bash +++ b/scripts/arch-run.bash @@ -209,7 +209,7 @@ env_add_errata () if [ -f "$ENV" ] && grep -q '^ERRATA_' <(env); then for line in $(grep '^ERRATA_' "$ENV"); do errata=${line%%=*} - test -v $errata && continue + [[ -n "${!errata}" ]] && continue eval export "$line" done elif [ ! -f "$ENV" ]; then @@ -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,13 @@ env_generate_errata () commit=${line%:*} minver=${line#*:} + if [ -z "$commit" ]; then + echo "Errata file $ERRATATXT corrupt. Missing commit on line: $line" + return 2 + fi + errata="ERRATA_$commit" - test -v $errata && continue + [[ -n "${!errata}" ]] && continue IFS=. read -r v p rest <<<"$minver" IFS=- read -r s x <<<"$rest" -- 2.17.0.484.g0c8726318c-goog