ctdb-scripts: Ignore shellcheck SC2181 warning (use of $?)
authorMartin Schwenke <martin@meltin.net>
Fri, 11 Aug 2017 02:49:32 +0000 (12:49 +1000)
committerAmitay Isaacs <amitay@samba.org>
Mon, 14 Aug 2017 03:15:25 +0000 (05:15 +0200)
Given the size of the command substitutions it would be less clear to
embed the assignments and substitutions inside a conditional.  It is
clearer if the exit code is checked afterwards.

However, do fix some untidy uses of != instead of -ne when comparing
with $?.  Make the code easier to understand by reversing the logic
and using -eq and ||.

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
ctdb/config/debug-hung-script.sh
ctdb/tools/ctdb_diagnostics
ctdb/tools/onnode

index da988c2f9134e03cad481d3cd3251b1e3f7e1f4c..2e3792c71109ea918bb811c2fb29ef84ccbe87ad 100755 (executable)
@@ -39,6 +39,8 @@ fi
     sed -r -n "s@.*-(.*(${pat}).*),([0-9]*).*@\3 \1@p" |
     while read pid name ; do
        trace=$(cat "/proc/${pid}/stack" 2>/dev/null)
+       # No! Checking the exit code afterwards is actually clearer...
+       # shellcheck disable=SC2181
        if [ $? -eq 0 ] ; then
            echo "---- Stack trace of interesting process ${pid}[${name}] ----"
            echo "$trace"
index eea6044429659c701c41f9973e8456c71a51cd0a..fb35ffb3e0a6de1586632d52c1575034bd4501f3 100755 (executable)
@@ -26,7 +26,9 @@ parse_options ()
 {
     temp=$(getopt -n "ctdb_diagnostics" -o "n:cwh" -l no-ads,help -- "$@")
 
-    [ $? != 0 ] && usage
+    # No! Checking the exit code afterwards is actually clearer...
+    # shellcheck disable=SC2181
+    [ $? -eq 0 ] || usage
 
     eval set -- "$temp"
 
index 0b31a826c6fb11e8272ee078b69fc591cb53c4d1..ca9673a95b9668981c053d07188684677ee41704 100755 (executable)
@@ -81,7 +81,9 @@ parse_options ()
     # Not on the previous line - local returns 0!
     temp=$(POSIXLY_CORRECT=1 getopt -n "$prog" -o "cf:hno:pqvPi" -l help -- "$@")
 
-    [ $? != 0 ] && usage
+    # No! Checking the exit code afterwards is actually clearer...
+    # shellcheck disable=SC2181
+    [ $? -eq 0 ] || usage
 
     eval set -- "$temp"
 
@@ -147,6 +149,8 @@ get_nodes_with_status ()
 
     if [ -z "$ctdb_status_output" ] ; then
        ctdb_status_output=$(ctdb -X status 2>&1)
+       # No! Checking the exit code afterwards is actually clearer...
+       # shellcheck disable=SC2181
        if [ $? -ne 0 ] ; then
            echo "${prog}: unable to get status of CTDB nodes" >&2
            echo "$ctdb_status_output" >&2