From b71becc1501f70f26ab854460d6f833d8f4b5302 Mon Sep 17 00:00:00 2001 From: Martin Schwenke Date: Fri, 11 Aug 2017 12:49:32 +1000 Subject: [PATCH] ctdb-scripts: Ignore shellcheck SC2181 warning (use of $?) 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 Reviewed-by: Amitay Isaacs --- ctdb/config/debug-hung-script.sh | 2 ++ ctdb/tools/ctdb_diagnostics | 4 +++- ctdb/tools/onnode | 6 +++++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/ctdb/config/debug-hung-script.sh b/ctdb/config/debug-hung-script.sh index da988c2f913..2e3792c7110 100755 --- a/ctdb/config/debug-hung-script.sh +++ b/ctdb/config/debug-hung-script.sh @@ -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" diff --git a/ctdb/tools/ctdb_diagnostics b/ctdb/tools/ctdb_diagnostics index eea60444296..fb35ffb3e0a 100755 --- a/ctdb/tools/ctdb_diagnostics +++ b/ctdb/tools/ctdb_diagnostics @@ -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" diff --git a/ctdb/tools/onnode b/ctdb/tools/onnode index 0b31a826c6f..ca9673a95b9 100755 --- a/ctdb/tools/onnode +++ b/ctdb/tools/onnode @@ -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