康神代码赏析

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,康神伟大!

Tags: ,

9 Comments »

RSS feed for comments on this post.

  1. 拜康神

    Comment by fishy — March 24, 2008 8:14 pm #

  2. 精品啊…

    Comment by hutuworm — March 24, 2008 8:29 pm #

  3. 我是土鳖

    Comment by hayate — March 24, 2008 10:26 pm #

  4. 写 >/dev/null 2&>1 的不一定就是土鳖,也可能是为了脚本的可移植性。除了 bash 外,好像没有认得 &> 的 shell

    Comment by Anonymous — March 24, 2008 10:50 pm #

  5. orz看不懂这个

    Comment by kisstar — March 25, 2008 1:37 am #

  6. 拜A core!康神伟大!

    Comment by Orz — March 25, 2008 5:44 am #

  7. bash不是能直接用 &>- 关闭吗? 何必那么写呢?

    Comment by zBS — March 29, 2008 4:14 am #

  8. 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 #

  9. 拜!!!

    Comment by bonehead — March 30, 2008 8:30 am #

Leave a comment

XHTML: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This weblog is licensed under a Creative Commons License.
Powered by WordPress. Theme based on Pool by Borja Fernandez.