康神代码赏析

March 24, 2008 6:41 pm GMT-0700 | 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: ,

14 Comments »

RSS feed for comments on this post.

  1. 拜康神

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

  2. 精品啊…

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

  3. 我是土鳖

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

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

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

  5. orz看不懂这个

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

  6. 拜A core!康神伟大!

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

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

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

  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 GMT-0700 #

  9. 拜!!!

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

  10. 反对,坚持习惯非土鳖也!呵呵!

    Comment by ddd — September 12, 2008 1:05 am GMT-0700 #

  11. 鸟哥的书里面就有这样的小技巧….

    Comment by york.zhuo — December 2, 2008 11:26 pm GMT-0700 #

  12. 这个2写shell的人都会吧……%
    无语了康神是伟大,你也不用这么拐着弯的骂他啊

    Comment by luren — March 1, 2009 10:59 pm GMT-0700 #

  13. 康神伟大。
    在南半球回忆康神的音容笑貌

    Comment by zhangxiaofeng — December 29, 2009 5:15 pm GMT-0700 #

  14. Once I had to change &> to the other one, for that /bin/sh is not bash…

    Comment by Aaron — November 17, 2010 3:08 am GMT-0700 #

Leave a comment

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

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