Skip to content

Commit

Permalink
Update zfs-replicate.sh
Browse files Browse the repository at this point in the history
add double quotes as per shellcheck suggestions
  • Loading branch information
tschettervictor authored Aug 24, 2024
1 parent 1156116 commit 5c33481
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions zfs-replicate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ check_old_log() {
## initialize index
local index=0
## find existing logs
for log in $(${FIND} ${LOGBASE} -maxdepth 1 -type f -name autorep-\*); do
for log in $("${FIND}" "${LOGBASE}" -maxdepth 1 -type f -name autorep-\*); do
## get file change time via stat (platform specific)
case "$(uname -s)" in
Linux|SunOS)
local fstat=$(stat -c %Z ${log})
local fstat=$(stat -c %Z "${log}")

Check warning on line 19 in zfs-replicate.sh

View workflow job for this annotation

GitHub Actions / runner / shellcheck

[shellcheck] reported by reviewdog 🐶 Declare and assign separately to avoid masking return values. Raw Output: ./zfs-replicate.sh:19:23: warning: Declare and assign separately to avoid masking return values. (ShellCheck.SC2155)
;;
*)
local fstat=$(stat -f %c ${log})
local fstat=$(stat -f %c "${log}")

Check warning on line 22 in zfs-replicate.sh

View workflow job for this annotation

GitHub Actions / runner / shellcheck

[shellcheck] reported by reviewdog 🐶 Declare and assign separately to avoid masking return values. Raw Output: ./zfs-replicate.sh:22:23: warning: Declare and assign separately to avoid masking return values. (ShellCheck.SC2155)
;;
esac
## append logs to array with creation time
Expand All @@ -28,21 +28,21 @@ check_old_log() {
let "index += 1"

Check warning on line 28 in zfs-replicate.sh

View workflow job for this annotation

GitHub Actions / runner / shellcheck

[shellcheck] reported by reviewdog 🐶 Instead of 'let expr', prefer (( expr )) . Raw Output: ./zfs-replicate.sh:28:9: info: Instead of 'let expr', prefer (( expr )) . (ShellCheck.SC2219)
done
## set log count
local lcount=${#logs[@]}
local lcount="${#logs[@]}"
## check count ... if greater than keep loop and delete
if [ $lcount -gt ${LOG_KEEP} ]; then

Check warning on line 33 in zfs-replicate.sh

View workflow job for this annotation

GitHub Actions / runner / shellcheck

[shellcheck] reported by reviewdog 🐶 Double quote to prevent globbing and word splitting. Raw Output: ./zfs-replicate.sh:33:10: info: Double quote to prevent globbing and word splitting. (ShellCheck.SC2086)

Check warning on line 33 in zfs-replicate.sh

View workflow job for this annotation

GitHub Actions / runner / shellcheck

[shellcheck] reported by reviewdog 🐶 Double quote to prevent globbing and word splitting. Raw Output: ./zfs-replicate.sh:33:22: info: Double quote to prevent globbing and word splitting. (ShellCheck.SC2086)
## build new array in descending age order and reset index
declare -a slogs=(); local index=0
## loop through existing array
for log in $(echo -e ${logs[@]:0} | sort -rn | cut -f2); do
for log in $(echo -e "${logs[@]:0}" | sort -rn | cut -f2); do
## append log to array
slogs[$index]=${log}

Check warning on line 39 in zfs-replicate.sh

View workflow job for this annotation

GitHub Actions / runner / shellcheck

[shellcheck] reported by reviewdog 🐶 $/${} is unnecessary on arithmetic variables. Raw Output: ./zfs-replicate.sh:39:19: info: $/${} is unnecessary on arithmetic variables. (ShellCheck.SC2004)
## increase index
let "index += 1"

Check warning on line 41 in zfs-replicate.sh

View workflow job for this annotation

GitHub Actions / runner / shellcheck

[shellcheck] reported by reviewdog 🐶 Instead of 'let expr', prefer (( expr )) . Raw Output: ./zfs-replicate.sh:41:13: info: Instead of 'let expr', prefer (( expr )) . (ShellCheck.SC2219)
done
## delete excess logs
printf "deleting old logs: %s ...\n" "${slogs[@]:${LOG_KEEP}}"
rm -rf ${slogs[@]:${LOG_KEEP}}
rm -rf "${slogs[@]:${LOG_KEEP}}"
fi
}

Expand Down

0 comments on commit 5c33481

Please sign in to comment.