Created
May 19, 2012 08:51
-
-
Save amdgigabyte/2730118 to your computer and use it in GitHub Desktop.
quick change your host
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 | |
# change my hosts | |
# | |
# USAGE # | |
# chost local(default) | |
# chost daily | |
# chost online | |
# | |
mode=$1 | |
if [[ $mode == '' ]];then | |
mode="local" | |
fi | |
function filtermode() { | |
if [ $(id -u) != "0" ];then | |
echo "必须以root权限运行此文件!" | |
end | |
fi | |
case $mode in | |
"daily"|"online"|"local") changemode $mode | |
;; | |
*) | |
echo 'you enter a wrong mode (please enter online ,daily, or local)' | |
end | |
;; | |
esac | |
} | |
function changemode () { | |
local inputmode=$1 | |
case $inputmode in | |
"daily") cat /etc/hosts.daily>/etc/hosts | |
;; | |
"online") cat /etc/hosts.online>/etc/hosts | |
;; | |
"local") cat /etc/hosts.local>/etc/hosts | |
;; | |
esac | |
echo 'mode changed to' $mode | |
end | |
} | |
function end() { | |
exit | |
} | |
filtermode $mode |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment