From 39f5445c2830a3d450dda6ee920ba74a985d4ec0 Mon Sep 17 00:00:00 2001 From: Asif Bacchus Date: Sun, 9 May 2021 08:44:47 -0600 Subject: [PATCH] perf: simpler iteration condition checking - less complex conditions - easier code to understand - cleans up extraneous delimiters - skips null entries immediately --- cfddns.sh | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/cfddns.sh b/cfddns.sh index 9030185..24a2fe2 100644 --- a/cfddns.sh +++ b/cfddns.sh @@ -369,10 +369,12 @@ else fi # iterate DNS records to update -dnsRecordsToUpdate="$dnsRecords$dnsSeparator" -while [ "$dnsRecordsToUpdate" != "${dnsRecordsToUpdate#*${dnsSeparator}}" ] && { [ -n "${dnsRecordsToUpdate%%${dnsSeparator}*}" ] || [ -n "${dnsRecordsToUpdate#*${dnsSeparator}}" ]; }; do +dnsRecordsToUpdate="$(printf '%s' "${1}" | sed "s/${dnsSeparator}*$//")$dnsSeparator" +while [ -n "$dnsRecordsToUpdate" ] && [ "$dnsRecordsToUpdate" != "$dnsSeparator" ]; do record="${dnsRecordsToUpdate%%${dnsSeparator}*}" dnsRecordsToUpdate="${dnsRecordsToUpdate#*${dnsSeparator}}" + + if [ -z "$record" ]; then continue; fi printf "updating record: %s\n" "$record" >>"$logFile" done @@ -411,9 +413,11 @@ elif [ "$ip6" -eq 1 ]; then fi # iterate hosts to update -while [ "$dnsRecordsToUpdate" != "${dnsRecordsToUpdate#*${dnsSeparator}}" ] && { [ -n "${dnsRecordsToUpdate%%${dnsSeparator}*}" ] || [ -n "${dnsRecordsToUpdate#*${dnsSeparator}}" ]; }; do +while [ -n "$dnsRecordsToUpdate" ] && [ "$dnsRecordsToUpdate" != "$dnsSeparator" ]; do record="${dnsRecordsToUpdate%%${dnsSeparator}*}" dnsRecordsToUpdate="${dnsRecordsToUpdate#*${dnsSeparator}}" + + if [ -z "$record" ]; then continue; fi printf "[%s] Processing %s... " "$(stamp)" "$record" >>"$logFile" # exit if curl/network error