> - dnsreply=$(dig +short -t srv _$1._$2.$d) > + dnsreply=$(dig +short -t srv _$1._$2.$d | sed s/.$// ) if you want to remove dot only then + dnsreply=$(dig +short -t srv _$1._$2.$d | sed 's/\.$//' ) But why is that trailing dot a problem? It's legal in DNS.