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>
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"
{
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"
# 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"
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