在 osx/linux 开发有时候要随时切换 hosts ,不想用软件,就自己写了个顺手的 shell 脚本,分享大家的同时,也请指教!
地址: https://github.com/leo-yi/hostsChangeShell

|  |      1skydiver      2015-09-04 00:00:11 +08:00 打码失败。。。 | 
|  |      2zhuangzhuang1988      2015-09-04 00:01:49 +08:00  1 http://oldj.github.io/SwitchHosts/ 这个挺不错的, GUI 的开源, python+wxPython 写的. | 
|  |      3xmoon      2015-09-04 00:14:27 +08:00 神奇打码 | 
|  |      4bdbai      2015-09-04 00:41:05 +08:00 via iPhone 大数字杀毒 啧啧 | 
|  |      5cxbig      2015-09-04 03:12:32 +08:00  1 好复杂。。。只是切换的话一条 sed 不就解决了,封装成 alias 或 function ,关闭或打开无非就是加减一个#的事。 | 
|  |      6ilotuo      2015-09-04 03:22:21 +08:00 via Android /go/分享创造  节点 话说这么简单功能真的需要这么多恶臭和判断么… | 
|      7cheneyeah      2015-09-04 09:43:38 +08:00 via iPhone  1 author 打错了... | 
|  |      8cattyhouse      2015-09-04 10:02:59 +08:00  1 感觉 LZ 只写了一半。。。而且判断超级简单的说,你这么切换了之后。。。想要还原的话怎么办,还要手动 cp 回去。。。 拉了屎却不擦屁股。 num=1 if [ $num -eq 1 ];then 这是一句废话。 直接 echo 不就行了? 其实非常简单的事情。。。 先备份原来的 hosts cp /etc/hosts /etc/hosts.orig 再创建一个自定义的 hosts.my ,内容: cat /etc/hosts.orig > /etc/hosts.my cat >> /etc/hosts.my << EOF xxxx google.com xxxx facebook.com xxxx xxxx EOF 然后再弄两个 alias alias hosts.orig="ln -sf /etc/hosts.orig /etc/hosts" alias hosts.my="in -sf /etc/hosts.my /etc/hosts" 是不是拉屎了也擦屁股了? | 
|  |      9cattyhouse      2015-09-04 10:10:45 +08:00 继续吐槽  echo 127.0.0.1 localhost > /etc/hosts 2>&1 不能这么 echo 的。。。 至少也要" " 用这个括号扩起来吧?用 echo 多行,可以这么干 echo "127.0.0.1 localhost xxxx google.com ... ... ... ... xxxx facebook.com" > /etc/hosts 或者最好: cat > /etc/hosts << EOF 127.0.0.1 localhost xxxx google.com ... ... ... ... xxxx facebook.com EOF | 
|  |      10ksc010      2015-09-04 10:54:15 +08:00 via iPhone http://git.oschina.net/ksc/hosts python 写的一个 | 
|  |      11bugsnail OP @cattyhouse 随便看了一下 shell 的语法,多谢指教了~ | 
|  |      14bugsnail OP @zhuangzhuang1988 就是不想用软件,太麻烦了... 不过还是谢谢~ | 
|  |      15bugsnail OP @cattyhouse 切换回之前的,多 cp 一个这样的 shell ,多一个别名,是一样的,当然可以设置 N 个.... | 
|  |      16pheyer      2015-09-04 13:29:01 +08:00 好像 OSX 下的 Alfred 也有相应的 WorkFlow ,更方便一些 | 
|  |      17cattyhouse      2015-09-04 13:30:44 +08:00 via iPhone @bugsnail 这玩意不需要 shell ,只需要用 ln 就可以了,也就是 link 。 | 
|  |      18omph      2015-09-04 17:49:38 +08:00 缩进有问题,差评! 最好能 5 行搞定 |