Dynamic ddns functionality on netlify

Iv read that :Dynamic ddns functionality on netlify
and other topics and repos.but there is something wrong to go with my code, the creating function works fine but the i can not delete the old one,please help me:

#!/usr/bin/env bash
DOMAIN=“abc.com
TTL_SECONDS=“120”
SUBDOMAIN=“def”

get a token at Netlify App

ACCESS_TOKEN=“REDACTED

whether or not

DO_IPV6=“1”
#apt install curl

constants

DNS_ZONE=“$(echo “$DOMAIN” | tr ‘.’ ‘_’)”
API=“https://api.netlify.com/api/v1
URL=“$API/dns_zones/$DNS_ZONE/dns_records?access_token=$ACCESS_TOKEN”

setup

CURL_FLAGS=“-sL”
curl=“curl $CURL_FLAGS”

fetch IP addresses

MY_IPV4=“$($curl 4.ipw.cn)” ||
{ echo “IPv4 Failed”; exit 4; }
if [ “$DO_IPV6” = “1” ]; then
MY_IPV6=“$($curl 6.ipw.cn)” ||
{ echo “IPv4 Failed from ‘ip’”; exit 5; }
[ -z “$MY_IPV6” ] && {
export DO_IPV6=“0”
echo “IPv6 Failed again from ‘ip’”
exit 6
}
fi
echo “$URL”

fetch current netlify DNS

CURRENT_DNS_REMOTE=$(curl -sL “$URL” | sed -n -r ‘/“type”: “A”/p; /“type”: “AAAA”/p’)
echo “remote ip is:”
echo “$CURRENT_DNS_REMOTE”

calc() {
echo “$CURRENT_DNS_ROMOTE” |
sed ‘s/[{}"\]//g’ | #
tr ‘:’ ‘,’ | #
sed -E ‘s/([^,]+),’“$1”‘([^,]*)/\2/p’ | #
sed ‘s/,$//’ #
}
setup_netlify_dns_record() {
echo “Setting up $SUBDOMAIN.$DOMAIN”
delete_netlify_dns_records_by_subdomain_if_exists “$SUBDOMAIN”
create_netlify_dns_records “$SUBDOMAIN” && echo “Done setting up $SUBDOMAIN.$DOMAIN”
}

delete_netlify_dns_records_by_subdomain_if_exists() {
if calc -e “map(select(.hostname == "$SUBDOMAIN.$DOMAIN" and .type == "A"))[0]” > /dev/null; then
RECORD_ID=“$(calc -r “map(select(.hostname == "$SUBDOMAIN.$DOMAIN"))[0].id”)”
curl -X DELETE “$API/dns_zones/$DNS_ZONE/dns_records/$RECORD_ID?access_token=$ACCESS_TOKEN” > /dev/null
fi
if [ “$DO_IPV6” = “1” ]; then
if calc -e “map(select(.hostname == "$SUBDOMAIN.$DOMAIN" and .type == "AAAA"))[0]” > /dev/null; then
RECORD_ID=“$(calc -r “map(select(.hostname == "$SUBDOMAIN.$DOMAIN"))[0].id”)”
curl -X DELETE “$API/dns_zones/$DNS_ZONE/dns_records/$RECORD_ID?access_token=$ACCESS_TOKEN” > /dev/null
fi
fi
}

create_netlify_dns_records() {

if [ "$DO_IPV6" = "1" ]; then
	PAYLOAD_IPv6="{\"type\":\"AAAA\",\"hostname\":\"$SUBDOMAIN\",\"value\":\"$MY_IPV6\",\"ttl\":\"$TTL_SECONDS\"}"
	echo "$PAYLOAD_IPv6" | curl -d @- -H 'content-type:application/json' "$API/dns_zones/$DNS_ZONE/dns_records?access_token=$ACCESS_TOKEN" > /dev/null

else
PAYLOAD_IPv4=“{"type":"A","hostname":"$SUBDOMAIN","value":"$MY_IPV4","ttl":"$TTL_SECONDS"}”
echo “$PAYLOAD_IPv4” | curl -d @- -H ‘content-type:application/json’ “$API/dns_zones/$DNS_ZONE/dns_records?access_token=$ACCESS_TOKEN” > /dev/null
fi
}

echo “IPv4 address is: $MY_IPV4”
[ “$DO_IPV6” = “1” ] && echo “IPv6 address is: $MY_IPV6”
setup_netlify_dns_record “$s” &
#create_netlify_dns_records
echo “Waiting for jobs to finish…”
wait

end

I’m not sure what you’re trying to do and why? Please share your use-case in detail.