开发者

automatically append executable line to script files

开发者 https://www.devze.com 2022-12-21 11:26 出处:网络
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

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

精彩评论

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

关注公众号