Skip to content

Instantly share code, notes, and snippets.

@wxianfeng
Created July 11, 2011 06:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save wxianfeng/1075384 to your computer and use it in GitHub Desktop.
Save wxianfeng/1075384 to your computer and use it in GitHub Desktop.
给ruby文件添加#coding:utf-8 如果不存在
#!/bin/bash
PATH=/usr/local/system/projects/guoyi
FIND_BIN=/usr/bin/find
SED_BIN=/bin/sed
CAT_BIN=/bin/cat
LOG=/tmp/foreach.log
$CAT_BIN /dev/null > $LOG
cd $PATH
function foreach(){
for f in `$FIND_BIN . -name "*.rb"` # 遍历所有.rb文件
do
if [ -d $f ] ; then
foreach $f
elif [ -f $f ] ; then
line=`$SED_BIN -n '1p' $f` # rb文件的第一行
if [[ "$line" =~ "utf-8" ]] ; then # 注意不能写成 $line , 必须是 "$line"
echo "next"
else
echo $f
echo $f >> $LOG
$CAT_BIN $f | $SED_BIN -e '1 i\#coding:utf-8' -i $f
fi
fi
done
}
foreach $PATH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment