康神代码赏析
March 24, 2008 6:41 pm | In Tech#!/bin/bash
OLDCONTENT=`find -type f -exec md5sum {} \; | md5sum`
svn up &> /dev/null
NEWCONTENT=`find -type f -exec md5sum {} \; | md5sum`
if [ "$NEWCONTENT" != "$OLDCONTENT" ]; then
# reload updated configuration
fi
以上是康神写的一个脚本的摘要。值得说的有两点:1、svn up 前后康神对整个目录的文件名和文件内容 md5 消化,这是确认目录是否有变化(包括文件改名)的一个好办法;2、康神用了 &> /dev/null 重定向 stdout 和 stderr,一般土鳖都写成 >/dev/null 2>&1,康神伟大!
9 Comments »
RSS feed for comments on this post.
Leave a comment
This weblog is licensed under a
Creative Commons License.
Powered by WordPress. Theme based on Pool by Borja Fernandez.
拜康神
Comment by fishy — March 24, 2008 8:14 pm #
精品啊…
Comment by hutuworm — March 24, 2008 8:29 pm #
我是土鳖
Comment by hayate — March 24, 2008 10:26 pm #
写 >/dev/null 2&>1 的不一定就是土鳖,也可能是为了脚本的可移植性。除了 bash 外,好像没有认得 &> 的 shell
Comment by Anonymous — March 24, 2008 10:50 pm #
orz看不懂这个
Comment by kisstar — March 25, 2008 1:37 am #
拜A core!康神伟大!
Comment by Orz — March 25, 2008 5:44 am #
bash不是能直接用 &>- 关闭吗? 何必那么写呢?
Comment by zBS — March 29, 2008 4:14 am #
md5所有文件也太慢了吧,不如这样:
#!/bin/bash
OLDVER=`svn info | grep Revision | gawk ‘{print $2}’`
NEWVER=`svn update | gawk ‘{print substr($3,0,length($3)-1)}’`
if [ "$OLDVER" != "$NEWVER" ]; then
# reload updated configuration
fi
Comment by hammer — March 29, 2008 6:29 pm #
拜!!!
Comment by bonehead — March 30, 2008 8:30 am #