ctdb-scripts: Avoid ShellCheck warning SC2295
authorMartin Schwenke <martin@meltin.net>
Fri, 27 May 2022 13:23:48 +0000 (23:23 +1000)
committerAmitay Isaacs <amitay@samba.org>
Fri, 22 Jul 2022 16:09:31 +0000 (16:09 +0000)
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 <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
ctdb/config/events/legacy/13.per_ip_routing.script
ctdb/tests/run_tests.sh
ctdb/tests/scripts/integration.bash
ctdb/tools/onnode

index e25647613bbc38074417a52a0606c777590502fa..d7949c6dedb7ec0e68e9c4c0ea2322396d2749d1 100755 (executable)
@@ -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"
index cb7884054aaa41b1f2ca9ef544de992527302dcf..ff431f8831f16c90c0a463af5606936cc087105c 100755 (executable)
@@ -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
                        */*/*)
index dbf9af0b346cb85ca1be363b2e3211f231f8d709..65e974e4e366c8e51dd1397cb0f11350d03feaed 100644 (file)
@@ -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
index f2be62e5af48b5b5f622c1a5887778d2c57c8455..425db8047ccbb24cb3dd04facf5fc4786ee8d045 100755 (executable)
@@ -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=""