btrfs-sync
btrfs-sync copied to clipboard
shellcheck errors and warnings
Great little tool, but could you make it shellcheck-clean?
$ shellcheck btrfs-sync
In btrfs-sync line 80:
[[ $? -ne 0 ]] && { echo "error parsing arguments"; exit 1; }
^-- SC2181 (style): Check exit code directly with e.g. 'if ! mycmd;', not indirectly with $?.
In btrfs-sync line 98:
DST="${@: -1}"
^--------^ SC2124 (warning): Assigning an array to a string! Assign as array, or use * instead of @ to concatenate.
In btrfs-sync line 101:
[[ "$SRC" =~ : ]] && {
^--^ SC2128 (warning): Expanding an array without an index only gives the first element.
In btrfs-sync line 102:
NET_SRC="$( sed 's|:.*||' <<<"$SRC" )"
^---------------------^ SC2001 (style): See if you can use ${variable//search/replace} instead.
^--^ SC2128 (warning): Expanding an array without an index only gives the first element.
In btrfs-sync line 103:
SRC="$( sed 's|.*:||' <<<"$SRC" )"
^-^ SC2178 (warning): Variable was used as an array but is now assigned a string.
^---------------------^ SC2001 (style): See if you can use ${variable//search/replace} instead.
^--^ SC2128 (warning): Expanding an array without an index only gives the first element.
In btrfs-sync line 107:
[[ "$SSH_SRC" != "" ]] && SRC_CMD=( ${SSH_SRC[@]} ) || SRC_CMD=( eval )
^------^ SC2128 (warning): Expanding an array without an index only gives the first element.
^-----------^ SC2206 (warning): Quote to prevent word splitting/globbing, or split robustly with mapfile or read -a.
In btrfs-sync line 108:
${SRC_CMD[@]} test -x "$SRC" &>/dev/null || {
^-----------^ SC2068 (error): Double quote array expansions to avoid re-splitting elements.
^--^ SC2128 (warning): Expanding an array without an index only gives the first element.
In btrfs-sync line 109:
[[ "$SSH_SRC" != "" ]] && echo "SSH access error to $NET_SRC. Do you have passwordless login setup, and adequate permissions for $SRC?"
^------^ SC2128 (warning): Expanding an array without an index only gives the first element.
^--^ SC2128 (warning): Expanding an array without an index only gives the first element.
In btrfs-sync line 110:
[[ "$SSH_SRC" == "" ]] && echo "Access error. Do you have adequate permissions for $SRC?"
^------^ SC2128 (warning): Expanding an array without an index only gives the first element.
^--^ SC2128 (warning): Expanding an array without an index only gives the first element.
In btrfs-sync line 116:
NET="$( sed 's|:.*||' <<<"$DST" )"
^---------------------^ SC2001 (style): See if you can use ${variable//search/replace} instead.
In btrfs-sync line 117:
DST="$( sed 's|.*:||' <<<"$DST" )"
^---------------------^ SC2001 (style): See if you can use ${variable//search/replace} instead.
In btrfs-sync line 120:
[[ "$SSH" != "" ]] && DST_CMD=( ${SSH[@]} ) || DST_CMD=( eval )
^--^ SC2128 (warning): Expanding an array without an index only gives the first element.
^-------^ SC2206 (warning): Quote to prevent word splitting/globbing, or split robustly with mapfile or read -a.
In btrfs-sync line 121:
${DST_CMD[@]} test -x "$DST" &>/dev/null || {
^-----------^ SC2068 (error): Double quote array expansions to avoid re-splitting elements.
In btrfs-sync line 122:
[[ "$SSH" != "" ]] && echo "SSH access error to $NET. Do you have passwordless login setup, and adequate permissions for $DST?"
^--^ SC2128 (warning): Expanding an array without an index only gives the first element.
In btrfs-sync line 123:
[[ "$SSH" == "" ]] && echo "Access error. Do you have adequate permissions for $DST?"
^--^ SC2128 (warning): Expanding an array without an index only gives the first element.
In btrfs-sync line 135:
${DST_CMD[@]} "pgrep -f btrfs\ receive &>/dev/null" && { echo "btrfs-sync already running at destination"; exit 1; }
^-----------^ SC2068 (error): Double quote array expansions to avoid re-splitting elements.
In btrfs-sync line 139:
while read entry; do SRCS+=( "$entry" ); done < <(
^--^ SC2162 (info): read without -r will mangle backslashes.
In btrfs-sync line 141:
for s in "${SRC[@]}"; do
^-------^ SC2068 (error): Double quote array expansions to avoid re-splitting elements.
^-------^ SC2145 (error): Argument mixes string and array. Use * or separate argument.
^-------^ SC2027 (warning): The surrounding quotes actually unquote this. Remove or escape them.
In btrfs-sync line 157:
"${SRC_CMD[@]}" type pbzip2 &>/dev/null && \
^-- SC2015 (info): Note that A && B || C is not if-then-else. C may run when A is true.
In btrfs-sync line 160:
ZIP=xz PIZ=unxz
^-^ SC2178 (warning): Variable was used as an array but is now assigned a string.
In btrfs-sync line 178:
while read entry; do
^--^ SC2162 (info): read without -r will mangle backslashes.
In btrfs-sync line 179:
DST_UUIDS+=( "$( sed 's=|.*==' <<<"$entry" )" )
^-----------------------^ SC2001 (style): See if you can use ${variable//search/replace} instead.
In btrfs-sync line 180:
DSTS+=( "$( sed 's=.*|==' <<<"$entry" )" )
^-----------------------^ SC2001 (style): See if you can use ${variable//search/replace} instead.
In btrfs-sync line 193:
local SRC="$1"
^-^ SC2178 (warning): Variable was used as an array but is now assigned a string.
In btrfs-sync line 200:
local LIST="$( "${SRC_CMD[@]}" sudo btrfs subvolume list -su "$SRC" )"
^--^ SC2155 (warning): Declare and assign separately to avoid masking return values.
^--^ SC2128 (warning): Expanding an array without an index only gives the first element.
In btrfs-sync line 204:
local PATH_=$( awk "{ if ( \$14 == \"$id\" ) print \$16 }" <<<"$LIST" )
^---^ SC2155 (warning): Declare and assign separately to avoid masking return values.
In btrfs-sync line 205:
local DATE=$( awk "{ if ( \$14 == \"$id\" ) print \$11, \$12 }" <<<"$LIST" )
^--^ SC2155 (warning): Declare and assign separately to avoid masking return values.
In btrfs-sync line 210:
local PATHS=( $( "${SRC_CMD[@]}" sudo btrfs su list -u "$SRC" | awk '{ print $11 }' ) )
^-- SC2207 (warning): Prefer mapfile or read -a to split command output (or quote to avoid splitting).
^--^ SC2128 (warning): Expanding an array without an index only gives the first element.
In btrfs-sync line 212:
SHOWP="$( "${SRC_CMD[@]}" sudo btrfs su sh "$( dirname "$SRC" )/$( basename "$p" )" 2>/dev/null )"
^---^ SC2178 (warning): Variable was used as an array but is now assigned a string.
^--^ SC2128 (warning): Expanding an array without an index only gives the first element.
In btrfs-sync line 213:
RXIDP="$( grep 'Received UUID' <<<"$SHOWP" | awk '{ print $3 }' )"
^---^ SC2178 (warning): Variable was used as an array but is now assigned a string.
^----^ SC2128 (warning): Expanding an array without an index only gives the first element.
In btrfs-sync line 214:
DATEP="$( grep 'Creation time' <<<"$SHOWP" | awk '{ print $3, $4 }' )"
^---^ SC2178 (warning): Variable was used as an array but is now assigned a string.
^----^ SC2128 (warning): Expanding an array without an index only gives the first element.
In btrfs-sync line 215:
[[ "$RXIDP" == "" ]] && continue
^----^ SC2128 (warning): Expanding an array without an index only gives the first element.
In btrfs-sync line 216:
PATH_RXID["$RXIDP"]="$p"
^----^ SC2128 (warning): Expanding an array without an index only gives the first element.
In btrfs-sync line 217:
DATE_RXID["$RXIDP"]="$DATEP"
^----^ SC2128 (warning): Expanding an array without an index only gives the first element.
^----^ SC2128 (warning): Expanding an array without an index only gives the first element.
In btrfs-sync line 225:
[[ "$PATH_" == "" ]] || [[ "$PATH_" == "$( basename "$SRC" )" ]] && continue
^--^ SC2128 (warning): Expanding an array without an index only gives the first element.
In btrfs-sync line 227:
local SECS=$( date -d "$DATE" +"%s" )
^--^ SC2155 (warning): Declare and assign separately to avoid masking return values.
In btrfs-sync line 235:
local SHOW="$( "${SRC_CMD[@]}" sudo btrfs subvolume show "$SRC" )"
^--^ SC2155 (warning): Declare and assign separately to avoid masking return values.
^--^ SC2128 (warning): Expanding an array without an index only gives the first element.
In btrfs-sync line 237:
local SRC_UUID="$( grep 'UUID:' <<<"$SHOW" | head -1 | awk '{ print $2 }' )"
^------^ SC2155 (warning): Declare and assign separately to avoid masking return values.
In btrfs-sync line 240:
local SRC_RXID="$( grep 'Received UUID' <<<"$SHOW" | awk '{ print $3 }' )"
^------^ SC2155 (warning): Declare and assign separately to avoid masking return values.
In btrfs-sync line 249:
local SRC="$1"
^-^ SC2178 (warning): Variable was used as an array but is now assigned a string.
In btrfs-sync line 250:
"${SRC_CMD[@]}" test -d "$SRC" || return
^--^ SC2128 (warning): Expanding an array without an index only gives the first element.
In btrfs-sync line 252:
exists_at_dst "$SRC" && { echov "* Skip existing '$SRC'"; return 0; }
^--^ SC2128 (warning): Expanding an array without an index only gives the first element.
^--^ SC2128 (warning): Expanding an array without an index only gives the first element.
In btrfs-sync line 254:
choose_seed "$SRC" # sets SEED
^--^ SC2128 (warning): Expanding an array without an index only gives the first element.
In btrfs-sync line 258:
local SEED_PATH="$( dirname "$SRC" )/$( basename $SEED )"
^-------^ SC2155 (warning): Declare and assign separately to avoid masking return values.
^--^ SC2128 (warning): Expanding an array without an index only gives the first element.
^---^ SC2086 (info): Double quote to prevent globbing and word splitting.
Did you mean:
local SEED_PATH="$( dirname "$SRC" )/$( basename "$SEED" )"
In btrfs-sync line 266:
[[ "$SEED_ARG" != "" ]] && echov -n " using seed '$SEED'"
^-------^ SC2128 (warning): Expanding an array without an index only gives the first element.
In btrfs-sync line 270:
sudo btrfs send -q ${SEED_ARG[@]} "$SRC" \
^------------^ SC2068 (error): Double quote array expansions to avoid re-splitting elements.
^--^ SC2128 (warning): Expanding an array without an index only gives the first element.
In btrfs-sync line 273:
| "${DST_CMD[@]}" "${PIZ[@]} | sudo btrfs receive \"$DST\" 2>&1 |(grep -v -e'^At subvol ' -e'^At snapshot '||true)" \
^-------^ SC2145 (error): Argument mixes string and array. Use * or separate argument.
In btrfs-sync line 275:
"${DST_CMD[@]}" sudo btrfs subvolume delete "$DST"/"$( basename "$SRC" )" 2>/dev/null
^--^ SC2128 (warning): Expanding an array without an index only gives the first element.
In btrfs-sync line 280:
DSTS+=("$DST/$( basename "$SRC" )")
^--^ SC2128 (warning): Expanding an array without an index only gives the first element.
In btrfs-sync line 282:
SEED_NEXT="$SRC"
^--^ SC2128 (warning): Expanding an array without an index only gives the first element.
In btrfs-sync line 309:
${DST_CMD[@]} sudo btrfs subvolume delete "${PRUNE_LIST[@]}" $SILENT
^-----------^ SC2068 (error): Double quote array expansions to avoid re-splitting elements.
^-----^ SC2086 (info): Double quote to prevent globbing and word splitting.
Did you mean:
${DST_CMD[@]} sudo btrfs subvolume delete "${PRUNE_LIST[@]}" "$SILENT"
In btrfs-sync line 316:
[[ "$( basename $src )" == "$( basename $dst )" ]] && { FOUND=1; break; }
^--^ SC2086 (info): Double quote to prevent globbing and word splitting.
^--^ SC2086 (info): Double quote to prevent globbing and word splitting.
Did you mean:
[[ "$( basename "$src" )" == "$( basename "$dst" )" ]] && { FOUND=1; break; }
In btrfs-sync line 320:
[[ "$DEL_LIST" != "" ]] && \
^-------^ SC2128 (warning): Expanding an array without an index only gives the first element.
In btrfs-sync line 322:
${DST_CMD[@]} sudo btrfs subvolume delete "${DEL_LIST[@]}" $SILENT
^-----------^ SC2068 (error): Double quote array expansions to avoid re-splitting elements.
^-----^ SC2086 (info): Double quote to prevent globbing and word splitting.
Did you mean:
${DST_CMD[@]} sudo btrfs subvolume delete "${DEL_LIST[@]}" "$SILENT"
For more information:
https://www.shellcheck.net/wiki/SC2068 -- Double quote array expansions to ...
https://www.shellcheck.net/wiki/SC2145 -- Argument mixes string and array. ...
https://www.shellcheck.net/wiki/SC2027 -- The surrounding quotes actually u...