> can't can't this in theory also get false positives if the current_hostname is just a prefix for an entry?

This is quite true. I thought about it but couldn't really come up with a reasonable counter-example that would break it.

>  What are we actually trying to match?

Basically given the entire contents of `/etc/hosts`, we're trying to any the line with an IP followed by the output of `hostname -f` (which we're calling the "current hostname") and change that to the target hostname.

I'm not sure, but I *think* that provided the entry following the IP is truly a FQDN, there's no way for a duplicate line to contain another host for which the FQDN is a prefix subset.

In other words, given FQDN of `host.datacenter.region.tld` there's no way we could have a `host.datacenter.region.tld.$FOO` that makes any sense.

But I'm totally open to suggestions if you see a way to make this better.