This covers the following:
SC2166: Prefer [ p ] && [ q ] as [ p -a q ] is not well defined.
SC2166: Prefer [ p ] || [ q ] as [ p -o q ] is not well defined.
POSIX agrees that -a and -o should not be used:
https://pubs.opengroup.org/onlinepubs/
9699919799/utilities/test.html
Fixing these doesn't cause much churn.
Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
oiface=$2
niface=$3
while read iface dest gw; do
- if [ "$niface" = "$iface" -o "$oiface" = "$iface" ] ; then
+ if [ "$niface" = "$iface" ] || [ "$oiface" = "$iface" ] ; then
ip route add "$dest" via "$gw" dev "$iface" >/dev/null 2>&1
fi
done <"${CTDB_BASE}/static-routes"
[ "$CTDB_PER_IP_ROUTING_TABLE_ID_LOW" -lt "$CTDB_PER_IP_ROUTING_TABLE_ID_HIGH" ] 2>/dev/null || \
die "error: CTDB_PER_IP_ROUTING_TABLE_ID_LOW[$CTDB_PER_IP_ROUTING_TABLE_ID_LOW] and/or CTDB_PER_IP_ROUTING_TABLE_ID_HIGH[$CTDB_PER_IP_ROUTING_TABLE_ID_HIGH] improperly configured"
-if [ "$CTDB_PER_IP_ROUTING_TABLE_ID_LOW" -le 253 -a \
- 255 -le "$CTDB_PER_IP_ROUTING_TABLE_ID_HIGH" ] ; then
+if [ "$CTDB_PER_IP_ROUTING_TABLE_ID_LOW" -le 253 ] && \
+ [ 255 -le "$CTDB_PER_IP_ROUTING_TABLE_ID_HIGH" ] ; then
die "error: range CTDB_PER_IP_ROUTING_TABLE_ID_LOW[$CTDB_PER_IP_ROUTING_TABLE_ID_LOW]..CTDB_PER_IP_ROUTING_TABLE_ID_HIGH[$CTDB_PER_IP_ROUTING_TABLE_ID_HIGH] must not include 253-255"
fi
for _o in $(export IFS="." ; echo $_ip) ; do
# The 2>/dev/null stops output from failures where an "octet"
# is not numeric. The test will still fail.
- if ! [ 0 -le $_o -a $_o -le 255 ] 2>/dev/null ; then
+ if ! [ 0 -le $_o ] && [ $_o -le 255 ] 2>/dev/null ; then
return 1
fi
_count=$((_count + 1))
fi
# Potentially update the new table id to be used. The
# redirect stops error spam for a non-numeric value.
- if [ "$_new" -le "$_t" -a \
- "$_t" -le "$CTDB_PER_IP_ROUTING_TABLE_ID_HIGH" ] 2>/dev/null ; then
+ if [ "$_new" -le "$_t" ] && \
+ [ "$_t" -le "$CTDB_PER_IP_ROUTING_TABLE_ID_HIGH" ] \
+ 2>/dev/null ; then
_new=$((_t + 1))
fi
done <"$rt_tables"
[ -n "$_iface" ] || continue
_table_id="${table_id_prefix}${_ip}"
- if [ -z "$(ip route show table "$_table_id" 2>/dev/null)" -o \
- "$1" = "force" ] ; then
+ if [ -z "$(ip route show table "$_table_id" 2>/dev/null)" ] || \
+ [ "$1" = "force" ] ; then
add_routing_for_ip "$_iface" "$_ip"
fi
done
fi
if $_ok ; then
- if [ $unhealthy_after -ne 1 -o $restart_every -ne 0 ] ; then
+ if [ $unhealthy_after -ne 1 ] || [ $restart_every -ne 0 ] ; then
ctdb_counter_init "$_progname"
fi
exit 0
# shellcheck disable=SC2031
nfs_restart_service ()
{
- if [ -z "$service_stop_cmd" -o -z "$service_start_cmd" ] ; then
+ if [ -z "$service_stop_cmd" ] || [ -z "$service_start_cmd" ] ; then
die "ERROR: Can not restart service \"${_progname}\" without corresponding service_start_cmd/service_stop_cmd settings"
fi
# SC2164: Use cd ... || exit in case cd fails.
# - Most hits are on known directories. Too
# much churn, maybe later.
- # SC2166: Prefer [ p ] && [ q ] as [ p -a q ] is not
- # well defined.
- # SC2166: Prefer [ p ] || [ q ] as [ p -o q ] is not
- # well defined.
- # - This can cause issues but the number of
- # true positives will be very low. Too much
- # churn, maybe later.
- _excludes="SC1090,SC1091,SC2162,SC2164,SC2166"
+ _excludes="SC1090,SC1091,SC2162,SC2164"
unit_test shellcheck --exclude="$_excludes" "$@"
else
echo "WARNING: shellcheck not installed, skipping test"
for i in $nodes; do
t2=$(onnode "$i" date +%s)
d=$((t2 - t))
- if [ "$d" -gt 30 -o "$d" -lt -30 ]; then
+ if [ "$d" -gt 30 ] || [ "$d" -lt -30 ]; then
error "time on node $i differs by $d seconds"
fi
done
node="$1"
fi
- if [ -n "$node" -a "$node" != "#DEAD" ] ; then
+ if [ -n "$node" ] && [ "$node" != "#DEAD" ] ; then
echo "$node"
else
echo "${prog}: \"node ${n}\" does not exist" >&2
local f="${CTDB_BASE}/nodes"
if [ -n "$ctdb_nodes_file" ] ; then
f="$ctdb_nodes_file"
- if [ ! -e "$f" -a "${f#/}" = "$f" ] ; then
+ if [ ! -e "$f" ] && [ "${f#/}" = "$f" ] ; then
# $f is relative, try in $CTDB_BASE
f="${CTDB_BASE}/${f}"
fi