I have a specific line in the hosts file that is used for my local Wordpress Multisite install, which looks like this:
127.0.0.1 localhost domain.dev s
if this is the line 7
sed -i '.bak' "7 s/$/ ${site_addr}.domain.dev/" /etc/hosts
but you can use the pattern matching (a bit safer) with
sed -i '.bak' "/127\.0\.0\.1/ s/$/ ${site_addr}.domain.dev/" /etc/hosts
i recommand to also first check if the domain is not already in