Skip to content

Instantly share code, notes, and snippets.

@amdgigabyte
Created May 19, 2012 08:51
Show Gist options
  • Save amdgigabyte/2730118 to your computer and use it in GitHub Desktop.
Save amdgigabyte/2730118 to your computer and use it in GitHub Desktop.
quick change your host
#! /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