linux 脚本加注解,添加头注释的shell脚本

虽然很简单,但付出了去做,很有成就感!

实现过程:读入所有.c文件,加入注释;

读入.h文件,加注释

把作者及功能写入文件,shell脚本读入配置文件。

选项(没有实现)

AI:开头已加注释的文件不再写入遇到好多问题,多半是对shell的语法不熟悉,比如判断命令[]与里面的语句没有空格开,

还有把命令也写在判断命令[]里了,

另一类问题就是基本工具使用的不熟练,sed找第一行弄了半天,读文件第一次用,而那个

什么exec根本没用过。

还好最后完成了两个版本:

第一个是把指定的文件夹中所有的C文件,加上头注释;

第二个是指定了要加注释的文件和配置文件,配置文件的格式如下

姓名

一些信息

就是第一行为姓名,其余行为注释信息。

嗯,现在有些混乱,但挺有成就的。

insert.one.sh#!/bin/sh

tmp=.beijing

#usage

if [ $# -ne 2 ]

then

echo "usage:insert.sh source_file info_file"

exit

fi

filename=$1

info=$2

# see if innotation had been added in the past

if  sed -n '1p' $filename | grep '\/\*' > /dev/null

then

#probably annotation inserted

echo $filename \\t"........it has already........."

exit

else

echo $filename \\t".......inserting........."

#   try to redirect std_output to fd 4

#   and then just echo ,no need to >>..

#   but not success!

#    exec 4<>$tmp

exec 8    read line

echo \/\* > $tmp

#file author

echo \ \* author\\t: \\t $line    >> $tmp

#echo \ \* date\\t: \\t `date`  >> $tmp

echo \ \* function\\t: >> $tmp

while :

do

read line         if [ $? -ne 0 ]

then

exec 8            break

fi

echo \ \* \\t \\t \\t \\t $line >> $tmp

done

#echo \ \* \\t\\t\\t\\t $3 >> $tmp

echo \ \*\/  >> $tmp

#    exec 4

#put $1 append to tmp

cat $filename >> $tmp

#put tmp to original file

cat $tmp > $filename

fi

#rm -f $tmpinsert.all.sh#!/bin/sh

tmp=.beijing

#usage

if [ $# -ne 3 ]

then

echo "usage:insert.sh dir author introduction"

exit

fi

for filename in `ls $1 | grep  '\.[ch]'`

do

#    echo $filename

if  sed -n '1p' $filename | grep '\/\*' > /dev/null

then

#probably annotation inserted

echo $filename \\t"........it has already........."

continue

else

echo $filename \\t".......inserting........."

#   try to redirect std_output to fd 4

#   and then just echo ,no need to >>..

#   but not success!

#    exec 4<>$tmp

#    exec >&4

echo \/\* > $tmp

#file author

echo \ \* author\\t: \\t $2    >> $tmp

#echo \ \* date\\t: \\t `date`  >> $tmp

echo \ \* function\\t: >> $tmp

#file function

echo \ \* \\t\\t\\t\\t $3 >> $tmp

echo \ \*\/         >> $tmp

#    exec 4

#put $1 append to tmp

cat $filename >> $tmp

#put tmp to original file

cat $tmp > $filename

fi

done

#rm -f $tmp

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值