From 19f347bff9e8d6e4f21c3578c15c09365c58c0c4 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Tue, 16 Nov 2021 10:22:49 -0800 Subject: [PATCH] Fix multiple shellcheck warnings The latest version of shellcheck reports the following warnings: check:307:9: warning: Quote arguments to unset so they're not glob expanded. [SC2184] check:505:10: warning: Quote arguments to unset so they're not glob expanded. [SC2184] check:506:10: warning: Quote arguments to unset so they're not glob expanded. [SC2184] check:539:11: warning: Quote arguments to unset so they're not glob expanded. [SC2184] new:102:19: note: Expansions inside ${..} need to be quoted separately, otherwise they match as patterns. [SC2295] common/rc:272:37: warning: -ne treats this as an arithmetic expression. Use != to compare as string (or expand explicitly with $((expr))). [SC2309] tests/block/008:65:10: warning: Quote arguments to unset so they're not glob expanded. [SC2184] tests/block/008:71:10: warning: Quote arguments to unset so they're not glob expanded. [SC2184] This patch fixes the above warnings. Signed-off-by: Bart Van Assche --- check | 8 ++++---- common/rc | 2 +- new | 2 +- tests/block/008 | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/check b/check index 0a4e539..fb400ca 100755 --- a/check +++ b/check @@ -304,7 +304,7 @@ _cleanup() { for key in "${!TEST_DEV_QUEUE_SAVED[@]}"; do value="${TEST_DEV_QUEUE_SAVED["$key"]}" echo "$value" >"${TEST_DEV_SYSFS}/queue/${key}" - unset TEST_DEV_QUEUE_SAVED["$key"] + unset "TEST_DEV_QUEUE_SAVED[$key]" done if [[ "${RESTORE_CPUS_ONLINE:-}" ]]; then @@ -502,8 +502,8 @@ _run_test() { if (( FALLBACK_DEVICE )); then cleanup_fallback_device - unset TEST_DEV_SYSFS_DIRS["${TEST_DEVS[0]}"] - unset TEST_DEV_PART_SYSFS_DIRS["${TEST_DEVS[0]}"] + unset "TEST_DEV_SYSFS_DIRS[${TEST_DEVS[0]}]" + unset "TEST_DEV_PART_SYSFS_DIRS[${TEST_DEVS[0]}]" TEST_DEVS=() fi @@ -536,7 +536,7 @@ _run_group() { group_device_requires if [[ -v SKIP_REASON ]]; then _output_notrun "${group}/*** => $(basename "$TEST_DEV")" - unset TEST_DEVS["$i"] + unset "TEST_DEVS[$i]" unset SKIP_REASON fi done diff --git a/common/rc b/common/rc index 85e6314..0528ce8 100644 --- a/common/rc +++ b/common/rc @@ -269,7 +269,7 @@ _require_test_dev_in_hotplug_slot() { local slt_cap slt_cap="$(setpci -s "${parent}" CAP_EXP+14.w)" - if [[ $((0x${slt_cap} & 0x60)) -ne 0x60 ]]; then + if [[ $((0x${slt_cap} & 0x60)) -ne $((0x60)) ]]; then SKIP_REASON="$TEST_DEV is not in a hot pluggable slot" return 1 fi diff --git a/new b/new index 51ec2c4..41f8b8d 100755 --- a/new +++ b/new @@ -99,7 +99,7 @@ fi for test in tests/"$group"/+([0-9]); do : done -seq=${test##tests/$group/+(0)} +seq=${test##tests/"${group}"/+(0)} test_name="${group}/$(printf "%03d" $((seq + 1)))" cat << EOF > "tests/${test_name}" diff --git a/tests/block/008 b/tests/block/008 index 671c532..7445f8f 100755 --- a/tests/block/008 +++ b/tests/block/008 @@ -62,13 +62,13 @@ test_device() { idx=$((RANDOM % ${#online_cpus[@]})) _offline_cpu "${online_cpus[$idx]}" offline_cpus+=("${online_cpus[$idx]}") - unset online_cpus["$idx"] + unset "online_cpus[$idx]" online_cpus=("${online_cpus[@]}") else idx=$((RANDOM % ${#offline_cpus[@]})) _online_cpu "${offline_cpus[$idx]}" online_cpus+=("${offline_cpus[$idx]}") - unset offline_cpus["$idx"] + unset "offline_cpus[$idx]" offline_cpus=("${offline_cpus[@]}") fi end_time=$(date +%s) -- 2.49.0