Skip to content

Instantly share code, notes, and snippets.

@DiegoSalazar
Last active December 28, 2015 19:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DiegoSalazar/7549415 to your computer and use it in GitHub Desktop.
Save DiegoSalazar/7549415 to your computer and use it in GitHub Desktop.
Quickly add a host to the hosts file.
#!/bin/bash
# quickly add a host to the hosts file
hostname="$1"
ipaddress="$2"
hostsfile="$3"
if [ -z "$ipaddress" ]; then
ipaddress="127.0.0.1"
fi
if [ -z "$hostsfile" ]; then
hostsfile="/etc/hosts"
fi
echo "$ipaddress $hostname" >> $hostsfile \
&& echo "Added \"$ipaddress $hostname\" to $hostsfile"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment