Skip to content

Instantly share code, notes, and snippets.

@rongself
Created November 4, 2014 04:02
Show Gist options
  • Save rongself/d025c75ac1afe2637f30 to your computer and use it in GitHub Desktop.
Save rongself/d025c75ac1afe2637f30 to your computer and use it in GitHub Desktop.
add host mapping to hosts file
#!/bin/bash
HOSTSPATH="/c/Windows/System32/drivers/etc/hosts"
if [[ $1 == "-h" || $1 == "--help" || $1 == "?" ]]; then
cat << HELP
Usage:
addhost
addhost [ip] [hostname]
addhost [-l|-e|-h]
Option:
-l show host file content
-e edit host file
-h|--help|? show this content
HELP
exit 0
fi
if [[ $1 == "-l" ]]; then
cat $HOSTSPATH
exit 0
fi
if [[ $1 == "-e" ]]; then
vim $HOSTSPATH
exit 0
fi
ip=$1
hostname=$2
if [[ -z "$ip" ]]; then
read -p "please input ip:" ip
fi
if [[ -z "$hostname" ]]; then
read -p "please input hostname:" hostname
fi
echo "$ip $hostname" >> $HOSTSPATH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment