shell|给代码添加版权信息

版权声明:本文系作者原创。未经许可,不得转载。

以前写的代码没有加上版权信息。后来要全部添加,一个一个添加当然很慢,于是写了一个脚本自动添加。 基本思路: 1、列出目录下所有文件 2、得到后缀名,根据后缀名添加不同格式的信息。 脚本如下:AddCopyrightInformation/addInfoToAllFile.sh#!/bin/bash [ "$1" ] || { echo "Usage: $0 /dir/path" exit 1 }_dir=$1filelist=`./script/getAllFile.sh $_dir`for file in $filelist do infotype=`./script/judgeInfoType.sh $file` ./script/addToSingleFile.sh $file $infotype doneAddCopyrightInformation/script/addToSingleFile.sh#!/bin/shfilepath=$1 infotype=$2if [ "$infotype"x = "asterisk"x ]; then cat ./info/cppinfo.txt $filepath > $filepath.tmp mv $filepath.tmp $filepath elif [ "$infotype"x = "octothorpe"x ]; then cat ./info/shellinfo.txt $filepath > $filepath.tmp mv $filepath.tmp $filepath elif [ "$infotype"x = "hyphen"x ]; then cat ./info/xmlinfo.txt $filepath > $filepath.tmp mv $filepath.tmp $filepath fiAddCopyrightInformation/script/getAllFile.sh #!/bin/bashnowdir=$1 find $nowdir -type fAddCopyrightInformation/script/judgeInfoType.sh#!/bin/bash [ "$1" ] || { echo "Usage: $0 filepath" exit 1 }filepath=$1filename=`basename $filepath` extensionname=${filename##*.}if [ "$extensionname"x = "cpp"x ]; then echo "asterisk" elif [ "$extensionname"x = "qml"x ]; then echo "asterisk" elif [ "$extensionname"x = "spec"x ]; then echo "octothorpe" elif [ "$extensionname"x = "h"x ]; then echo "asterisk" elif [ "$extensionname"x = "pro"x ]; then echo "octothorpe" elif [ "$extensionname"x = "pri"x ]; then echo "octothorpe" elif [ "$extensionname"x = "js"x ]; then echo "asterisk" fiAddCopyrightInformation/info/cppinfo.txt/*

  • This file is part of cmos-compositor
    *
  • Copyright (C) 2014 Beijing Yuan Xin Technology Co.,Ltd. All rights reserved.
    *
  • Authors:
  • Peng Huaping
  • Xie Yan
  • Li Jing
  • Liu Jiawei
  • This software, including documentation, is protected by copyright controlled
  • by Beijing Yuan Xin Technology Co.,Ltd. All rights are reserved.
    */
    【shell|给代码添加版权信息】AddCopyrightInformation/info/shellinfo.txt
    #
    # This file is part of cmos-compositor
    #
    # Copyright (C) 2014 Beijing Yuan Xin Technology Co.,Ltd. All rights reserved.
    #
    # Authors:
    # Peng Huaping
    # Xie Yan
    # Li Jing
    # Liu Jiawei
    #
    # This software, including documentation, is protected by copyright controlled
    # by Beijing Yuan Xin Technology Co.,Ltd. All rights are reserved.
    #
    AddCopyrightInformation/info/xmlinfo.txt














    使用方式如下:
    1、将需要添加版权信息的源代码备份。
    2、进入到脚本目录,修改info目录下的三个txt文件,将文件中的模块名称和作者名称修改,保存退出。然后,执行脚本:
    cd AddCopyrightInformation ./addInfoToAllFile.sh /home/simba/virtualshare/cmos-photos 注:参数为需要添加版权信息的模块的目录,最好是绝对路径.

    3、程序执行完成之后,检查确认。
    注:新建的文件,可以使用IDE自动添加。

    推荐阅读