开发者

automatically append executable line to script files

My hosting company requires me to put #!/usr/local/bin/ruby at the top of every R开发者_JAVA百科B file. Is there an easy way to use sed recursively or something that can go through and append this to the top of every rb file?


awk

$ awk 'NR==1{$0="#!/usr/local/bin/ruby\n"$0 }1' file > temp; mv temp file;

sed

sed -i.bak '1 i #!/usr/local/bin/ruby' file

to do it recursively, you can use find

find /path -type f -iname "*.rb" | while read -r FILE
do
    sed -i.bak '1 i #!/usr/local/bin/ruby' $FILE 
    # awk 'NR==1{$0="#!/usr/local/bin/ruby\n"$0 }1' >temp ; mv temp $FILe
done
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜