These `sed` expressions have too many backslashes now, and the $hosts won't be expanded since it's in a single-quoted string. I think this would work:

``` Bash
sed -e 's/^\(127\.0\.0\.1.*\)$/\1 '"$hosts"'/' -i.bak /etc/hosts
sed -e 's/^\(::1.*\)$/\1 '"$hosts"'/' -i.bak /etc/hosts
```