« 批评一下 PHP
康神代码赏析
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
,康神伟大!
14 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 GMT-0700 #
精品啊…
Comment by hutuworm — March 24, 2008 8:29 pm GMT-0700 #
我是土鳖
Comment by hayate — March 24, 2008 10:26 pm GMT-0700 #
写 >/dev/null 2&>1 的不一定就是土鳖,也可能是为了脚本的可移植性。除了 bash 外,好像没有认得 &> 的 shell
Comment by Anonymous — March 24, 2008 10:50 pm GMT-0700 #
orz看不懂这个
Comment by kisstar — March 25, 2008 1:37 am GMT-0700 #
拜A core!康神伟大!
Comment by Orz — March 25, 2008 5:44 am GMT-0700 #
bash不是能直接用 &>- 关闭吗? 何必那么写呢?
Comment by zBS — March 29, 2008 4:14 am GMT-0700 #
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 #
拜!!!
Comment by bonehead — March 30, 2008 8:30 am GMT-0700 #
反对,坚持习惯非土鳖也!呵呵!
Comment by ddd — September 12, 2008 1:05 am GMT-0700 #
鸟哥的书里面就有这样的小技巧….
Comment by york.zhuo — December 2, 2008 11:26 pm GMT-0700 #
这个2写shell的人都会吧……%
无语了康神是伟大,你也不用这么拐着弯的骂他啊
Comment by luren — March 1, 2009 10:59 pm GMT-0700 #
康神伟大。
在南半球回忆康神的音容笑貌
Comment by zhangxiaofeng — December 29, 2009 5:15 pm GMT-0700 #
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 #