From db37043bc5c67e536bcaaf1941cb12ec2e72efc9 Mon Sep 17 00:00:00 2001 From: Martin Schwenke Date: Fri, 27 May 2022 23:23:48 +1000 Subject: [PATCH] ctdb-scripts: Avoid ShellCheck warning SC2295 For example: In /home/martins/samba/samba/ctdb/tools/onnode line 304: [ "$nodes" != "${nodes%[ ${nl}]*}" ] && verbose=true ^---^ SC2295 (info): Expansions inside ${..} need to be quoted separately, otherwise they match as patterns. Did you mean: [ "$nodes" != "${nodes%[ "${nl}"]*}" ] && verbose=true For more information: https://www.shellcheck.net/wiki/SC2295 -- Expansions inside ${..} need to b... Who knew? Thanks ShellCheck! Signed-off-by: Martin Schwenke Reviewed-by: Amitay Isaacs --- ctdb/config/events/legacy/13.per_ip_routing.script | 2 +- ctdb/tests/run_tests.sh | 6 +++--- ctdb/tests/scripts/integration.bash | 4 +++- ctdb/tools/onnode | 4 ++-- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/ctdb/config/events/legacy/13.per_ip_routing.script b/ctdb/config/events/legacy/13.per_ip_routing.script index e25647613bb..d7949c6dedb 100755 --- a/ctdb/config/events/legacy/13.per_ip_routing.script +++ b/ctdb/config/events/legacy/13.per_ip_routing.script @@ -346,7 +346,7 @@ remove_bogus_routes () # be done with grep, but let's do it with shell prefix removal # to avoid unnecessary processes. This falls through if # "@${_i}@" isn't present in $_ips. - [ "$_ips" = "${_ips#*@${_i}@}" ] || continue + [ "$_ips" = "${_ips#*@"${_i}"@}" ] || continue echo "Removing ip rule/routes for unhosted public address $_i" del_routing_for_ip "$_i" diff --git a/ctdb/tests/run_tests.sh b/ctdb/tests/run_tests.sh index cb7884054aa..ff431f8831f 100755 --- a/ctdb/tests/run_tests.sh +++ b/ctdb/tests/run_tests.sh @@ -235,7 +235,7 @@ run_one_test () local test_dir test_suite_dir reldir test_dir=$(cd "$CTDB_TEST_DIR" && pwd) test_suite_dir=$(cd "$CTDB_TEST_SUITE_DIR" && pwd) - reldir="${test_suite_dir#${test_dir}/}" + reldir="${test_suite_dir#"${test_dir}"/}" export CTDB_TEST_TMP_DIR="${test_state_dir}/${reldir}" rm -rf "$CTDB_TEST_TMP_DIR" @@ -260,7 +260,7 @@ run_tests () # Can't find it? Check relative to CTDB_TEST_DIR. # Strip off current directory from beginning, # if there, just to make paths more friendly. - f="${CTDB_TEST_DIR#${PWD}/}/${f}" + f="${CTDB_TEST_DIR#"${PWD}"/}/${f}" fi if [ -d "$f" ] ; then @@ -268,7 +268,7 @@ run_tests () test_dir=$(cd "$CTDB_TEST_DIR" && pwd) dir=$(cd "$f" && pwd) - reldir="${dir#${test_dir}/}" + reldir="${dir#"${test_dir}"/}" case "$reldir" in */*/*) diff --git a/ctdb/tests/scripts/integration.bash b/ctdb/tests/scripts/integration.bash index dbf9af0b346..65e974e4e36 100644 --- a/ctdb/tests/scripts/integration.bash +++ b/ctdb/tests/scripts/integration.bash @@ -469,8 +469,10 @@ node_has_status () while read -r line ; do # This needs to be done in 2 steps to # avoid false matches. - local line_bits="${line#|${pnn}|*|}" + local line_bits="${line#|"${pnn}"|*|}" [ "$line_bits" = "$line" ] && continue + # shellcheck disable=SC2295 + # This depends on $bits being a pattern [ "${line_bits#${bits}}" != "$line_bits" ] && \ return 0 done diff --git a/ctdb/tools/onnode b/ctdb/tools/onnode index f2be62e5af4..425db8047cc 100755 --- a/ctdb/tools/onnode +++ b/ctdb/tools/onnode @@ -148,7 +148,7 @@ get_nodes_with_status () fi local nl=" " - ctdb_status_output="${ctdb_status_output#*${nl}}" + ctdb_status_output="${ctdb_status_output#*"${nl}"}" fi ( @@ -301,7 +301,7 @@ else # If $nodes contains a space or a newline then assume multiple nodes. nl=" " - [ "$nodes" != "${nodes%[ ${nl}]*}" ] && verbose=true + [ "$nodes" != "${nodes%[ "${nl}"]*}" ] && verbose=true fi pids="" -- 2.11.4.GIT