Created
November 4, 2014 04:02
-
-
Save rongself/d025c75ac1afe2637f30 to your computer and use it in GitHub Desktop.
add host mapping to hosts file
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 | |
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