Skip to content

Instantly share code, notes, and snippets.

@ekka21
Last active August 29, 2015 14:10
Show Gist options
  • Save ekka21/0a3b0b0752e40f714cfe to your computer and use it in GitHub Desktop.
Save ekka21/0a3b0b0752e40f714cfe to your computer and use it in GitHub Desktop.
Add a new /etc/hosts script
#!/bin/bash
echo "127.0.0.1 will be used if IP-Address is blank.";
read -p "IP-Address: " IP_ADDRESS
read -p "Site Name: " SITE_NAME
#Add a new /etc/hosts
if [ -n "$IP_ADDRESS" ]; then
#not empty
sudo -- sh -c "echo ${IP_ADDRESS} ${SITE_NAME} >> /etc/hosts"
else
sudo -- sh -c "echo 127.0.0.1 ${SITE_NAME} >> /etc/hosts"
fi
#Clear cache
dscacheutil -flushcache;
#Display a result
cat /etc/hosts;
echo '';
echo '---------------------------';
echo ${SITE_NAME} . " added!";
echo '---------------------------';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment