Last active
August 29, 2015 14:10
-
-
Save ekka21/0a3b0b0752e40f714cfe to your computer and use it in GitHub Desktop.
Add a new /etc/hosts script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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