- 浏览: 4734815 次
- 性别:
- 来自: 上海
文章分类
最新评论
-
bzhao:
你也应该可以这样:(not tested)./rbtunnel ...
在Bash脚本中怎么关闭文件描述符? -
bzhao:
如果有A进程原代码情况下,通过如下调用,把他的子进程继承关闭则 ...
在Bash脚本中怎么关闭文件描述符? -
Master-Gao:
楼主咋没分析下源码呢?
我使用过的Linux命令之dirname - 截取给定路径的目录部分 -
jiedushi:
tail -F 就可以吧
Linux下实时跟踪log4j日志文件的bash脚本 - 增强了tail -f的功能 -
java_is_new:
新手学习了,就是不明白为一个网卡配多个ip有什么用
我使用过的Linux命令之ifconfig - 网络配置命令
Linux下把多个子目录中的源代码添加到CVS仓库的Bash脚本
本文链接:http://codingstandards.iteye.com/blog/792113 (转载请注明出处)
要求描述
在src目录下,包含多个子目录,每个子目录下都有C/C++的源代码,现在要把它们自动加入到CVS仓库中,只能将源文件(比如.h文件,.c文件,.hpp文件,.cpp文件,makefile)提交,不能包含编译中间产生的临时文件(比如.o文件)和最终执行文件。
当把一个目录添加CVS仓库之后,目录中会增加一个CVS目录,CVS目录中的几个文件(Entries、Repository和Root)是用来保存一些cvs版本管理信息的。要注意的是cvs这个东西有个问题,使用cvs add CVS时也可以将CVS这个目录添加到CVS仓库中,因此要避免这种情况。
版本演化
版本0
基本思路:遍历每一个子目录,CVS目录除外,如果一个子目录中没有CVS子目录,那么需要添加该目录,否则忽略;然后把该子目录下的源文件添加到CVS仓库中。如下所示:
文件:add2cvs0.sh
#!/bin/sh for d in * do if [ -d "$d" -a "$d" != "CVS" ]; then if [ ! -d "$d/CVS" ]; then cvs add "$d" fi cvs add "$d/*.h" "$d/*.c" "$d/*.hpp" "$d/*.cpp" "$d/makefile" "$d/*.java" "$d/*.html" fi done cvs commit
试一下,发现它会把*.h本身作为一个文件名传递给cvs add命令,实际上并不是每个目录中都包含这几种扩展名的文件。因为有些是纯C编写的,有些是用C++的。
[root@rhel55 src]# ./add2cvs0.sh
cvs [server aborted]: Couldn't open RCS file /CVSWEBX/web_spider/src/test0/*.h,v: Invalid argument
cvs [server aborted]: Couldn't open RCS file /CVSWEBX/web_spider/src/test1/*.h,v: Invalid argument
cvs [server aborted]: Couldn't open RCS file /CVSWEBX/web_spider/src/test2/*.h,v: Invalid argument
cvs [server aborted]: Couldn't open RCS file /CVSWEBX/web_spider/src/test3/*.h,v: Invalid argument
cvs [server aborted]: Couldn't open RCS file /CVSWEBX/web_spider/src/test4/*.h,v: Invalid argument
cvs [server aborted]: Couldn't open RCS file /CVSWEBX/web_spider/src/test5/*.h,v: Invalid argument
cvs [server aborted]: Couldn't open RCS file /CVSWEBX/web_spider/src/test6/*.h,v: Invalid argument
cvs [server aborted]: Couldn't open RCS file /CVSWEBX/web_spider/src/test7/*.h,v: Invalid argument
cvs [server aborted]: Couldn't open RCS file /CVSWEBX/web_spider/src/test8/*.h,v: Invalid argument
cvs commit: Examining .
cvs commit: Examining test0
cvs commit: Examining test1
cvs commit: Examining test2
cvs commit: Examining test3
cvs commit: Examining test4
cvs commit: Examining test5
cvs commit: Examining test6
cvs commit: Examining test7
cvs commit: Examining test8
[root@rhel55 src]#
版本1
改进思路:把cvs add 后面的那几种通配符表示的文件名,改用Bash中的大括号表示。比如*.{h,c}实际相当于$.h *.c的简写法。
文件:add2cvs1.sh
#!/bin/sh for d in * do if [ -d "$d" -a "$d" != "CVS" ]; then if [ ! -d "$d/CVS" ]; then cvs add "$d" fi #cvs add "$d/*.h" "$d/*.c" "$d/*.hpp" "$d/*.cpp" "$d/makefile" "$d/*.java" "$d/*.html" cvs add $d/*.{h,c,hpp,cpp,java,html,xml} fi done cvs commit
试一下,还是不行,跟上面一样。因为只是把参数改一下写法,实际上是等同的。
[root@rhel55 src]# ./add2cvs1.sh
cvs [server aborted]: Couldn't open RCS file /CVSWEBX/web_spider/src/test0/*.h,v: Invalid argument
cvs [server aborted]: Couldn't open RCS file /CVSWEBX/web_spider/src/test1/*.h,v: Invalid argument
cvs [server aborted]: Couldn't open RCS file /CVSWEBX/web_spider/src/test2/*.h,v: Invalid argument
cvs [server aborted]: Couldn't open RCS file /CVSWEBX/web_spider/src/test3/*.h,v: Invalid argument
cvs [server aborted]: Couldn't open RCS file /CVSWEBX/web_spider/src/test4/*.h,v: Invalid argument
cvs [server aborted]: Couldn't open RCS file /CVSWEBX/web_spider/src/test5/*.h,v: Invalid argument
cvs [server aborted]: Couldn't open RCS file /CVSWEBX/web_spider/src/test6/*.h,v: Invalid argument
cvs [server aborted]: Couldn't open RCS file /CVSWEBX/web_spider/src/test7/*.h,v: Invalid argument
cvs [server aborted]: Couldn't open RCS file /CVSWEBX/web_spider/src/test8/*.h,v: Invalid argument
cvs commit: Examining .
cvs commit: Examining test0
cvs commit: Examining test1
cvs commit: Examining test2
cvs commit: Examining test3
cvs commit: Examining test4
cvs commit: Examining test5
cvs commit: Examining test6
cvs commit: Examining test7
cvs commit: Examining test8
[root@rhel55 src]#
版本2
改进思路:直接使用通配符表示的文件参数(比如*.h)在传递的时候,如果没有可以匹配的文件,那么Bash就会把该参数本身传递。因此想到先用ls命令把这些文件列出来,把输出作为参数来传递。
文件:add2cvs2.sh
#!/bin/sh for d in * do if [ -d "$d" -a "$d" != "CVS" ]; then if [ ! -d "$d/CVS" ]; then cvs add "$d" fi #cvs add "$d/*.h" "$d/*.c" "$d/*.hpp" "$d/*.cpp" "$d/makefile" "$d/*.java" "$d/*.html" cvs add $(ls $d/*.{h,c,hpp,cpp,java,html,xml,sh} $d/makefile) fi done cvs commit
试一下,发现效果还不错。如果匹配的文件不存在,ls会报错,错误信息是输出在标准错误设备上的,而$(ls *.h)只把标准输出的信息变成字符串。
[root@rhel55 src]# ./add2cvs2.sh
ls: test0/*.h: 没有那个文件或目录
ls: test0/*.hpp: 没有那个文件或目录
ls: test0/*.cpp: 没有那个文件或目录
ls: test0/*.java: 没有那个文件或目录
ls: test0/*.html: 没有那个文件或目录
ls: test0/*.xml: 没有那个文件或目录
ls: test0/makefile: 没有那个文件或目录
cvs server: test0/test0.c already exists, with version number 1.1
cvs server: test0/test0.sh already exists, with version number 1.1
ls: test1/*.h: 没有那个文件或目录
ls: test1/*.c: 没有那个文件或目录
ls: test1/*.hpp: 没有那个文件或目录
ls: test1/*.java: 没有那个文件或目录
ls: test1/*.html: 没有那个文件或目录
ls: test1/*.xml: 没有那个文件或目录
cvs server: test1/makefile already exists, with version number 1.1
cvs server: test1/test1.cpp already exists, with version number 1.1
cvs server: test1/test1.sh already exists, with version number 1.1
ls: test2/*.h: 没有那个文件或目录
ls: test2/*.c: 没有那个文件或目录
ls: test2/*.hpp: 没有那个文件或目录
ls: test2/*.java: 没有那个文件或目录
ls: test2/*.html: 没有那个文件或目录
ls: test2/*.xml: 没有那个文件或目录
ls: test2/*.sh: 没有那个文件或目录
cvs server: test2/makefile already exists, with version number 1.1
cvs server: test2/test2.cpp already exists, with version number 1.1
ls: test3/*.h: 没有那个文件或目录
ls: test3/*.c: 没有那个文件或目录
ls: test3/*.hpp: 没有那个文件或目录
ls: test3/*.java: 没有那个文件或目录
ls: test3/*.html: 没有那个文件或目录
ls: test3/*.xml: 没有那个文件或目录
ls: test3/*.sh: 没有那个文件或目录
cvs server: test3/makefile already exists, with version number 1.1
cvs server: test3/test3.cpp already exists, with version number 1.1
ls: test4/*.h: 没有那个文件或目录
ls: test4/*.hpp: 没有那个文件或目录
ls: test4/*.cpp: 没有那个文件或目录
ls: test4/*.html: 没有那个文件或目录
ls: test4/*.xml: 没有那个文件或目录
ls: test4/makefile: 没有那个文件或目录
cvs server: test4/test4.c already exists, with version number 1.1
cvs server: test4/Test4.java already exists, with version number 1.1
cvs server: test4/test4.sh already exists, with version number 1.1
ls: test5/*.h: 没有那个文件或目录
ls: test5/*.c: 没有那个文件或目录
ls: test5/*.hpp: 没有那个文件或目录
ls: test5/*.java: 没有那个文件或目录
ls: test5/*.html: 没有那个文件或目录
ls: test5/*.xml: 没有那个文件或目录
ls: test5/*.sh: 没有那个文件或目录
cvs server: test5/makefile already exists, with version number 1.1
cvs server: test5/test5.cpp already exists, with version number 1.1
ls: test6/*.h: 没有那个文件或目录
ls: test6/*.c: 没有那个文件或目录
ls: test6/*.hpp: 没有那个文件或目录
ls: test6/*.java: 没有那个文件或目录
ls: test6/*.xml: 没有那个文件或目录
ls: test6/*.sh: 没有那个文件或目录
cvs server: test6/index.html already exists, with version number 1.1
cvs server: test6/makefile already exists, with version number 1.1
cvs server: test6/test6.cpp already exists, with version number 1.1
ls: test7/*.h: 没有那个文件或目录
ls: test7/*.c: 没有那个文件或目录
ls: test7/*.hpp: 没有那个文件或目录
ls: test7/*.java: 没有那个文件或目录
ls: test7/*.html: 没有那个文件或目录
ls: test7/*.sh: 没有那个文件或目录
cvs server: test7/makefile already exists, with version number 1.1
cvs server: test7/spider.xml already exists, with version number 1.1
cvs server: test7/test7.cpp already exists, with version number 1.1
ls: test8/*.h: 没有那个文件或目录
ls: test8/*.c: 没有那个文件或目录
ls: test8/*.hpp: 没有那个文件或目录
ls: test8/*.java: 没有那个文件或目录
ls: test8/*.html: 没有那个文件或目录
ls: test8/*.xml: 没有那个文件或目录
ls: test8/*.sh: 没有那个文件或目录
cvs server: test8/makefile already exists, with version number 1.1
cvs server: test8/test8.cpp already exists, with version number 1.1
cvs commit: Examining .
cvs commit: Examining test0
cvs commit: Examining test1
cvs commit: Examining test2
cvs commit: Examining test3
cvs commit: Examining test4
cvs commit: Examining test5
cvs commit: Examining test6
cvs commit: Examining test7
cvs commit: Examining test8
[root@rhel55 src]#
版本3
改进思路:把ls的错误输出摒蔽掉,通过将标准错误输出重定向到/dev/null就可以做到了。
文件:add2cvs.sh
#!/bin/sh for d in * do if [ -d "$d" -a "$d" != "CVS" ]; then if [ ! -d "$d/CVS" ]; then cvs add "$d" fi #cvs add "$d/*.h" "$d/*.c" "$d/*.hpp" "$d/*.cpp" "$d/makefile" "$d/*.java" "$d/*.html" cvs add $(ls $d/*.{h,c,hpp,cpp,java,html,xml,sh} $d/makefile 2>/dev/null) fi done cvs commit
试一下,目标基本达到。
[root@rhel55 src]# ./add2cvs.sh
cvs server: test0/test0.c already exists, with version number 1.1
cvs server: test0/test0.sh already exists, with version number 1.1
cvs server: test1/makefile already exists, with version number 1.1
cvs server: test1/test1.cpp already exists, with version number 1.1
cvs server: test1/test1.sh already exists, with version number 1.1
cvs server: test2/makefile already exists, with version number 1.1
cvs server: test2/test2.cpp already exists, with version number 1.1
cvs server: test3/makefile already exists, with version number 1.1
cvs server: test3/test3.cpp already exists, with version number 1.1
cvs server: test4/test4.c already exists, with version number 1.1
cvs server: test4/Test4.java already exists, with version number 1.1
cvs server: test4/test4.sh already exists, with version number 1.1
cvs server: test5/makefile already exists, with version number 1.1
cvs server: test5/test5.cpp already exists, with version number 1.1
cvs server: test6/index.html already exists, with version number 1.1
cvs server: test6/makefile already exists, with version number 1.1
cvs server: test6/test6.cpp already exists, with version number 1.1
cvs server: test7/makefile already exists, with version number 1.1
cvs server: test7/spider.xml already exists, with version number 1.1
cvs server: test7/test7.cpp already exists, with version number 1.1
cvs server: test8/makefile already exists, with version number 1.1
cvs server: test8/test8.cpp already exists, with version number 1.1
cvs commit: Examining .
cvs commit: Examining test0
cvs commit: Examining test1
cvs commit: Examining test2
cvs commit: Examining test3
cvs commit: Examining test4
cvs commit: Examining test5
cvs commit: Examining test6
cvs commit: Examining test7
cvs commit: Examining test8
[root@rhel55 src]#
- add2cvs.rar (944 Bytes)
- 下载次数: 2
发表评论
-
在Linux下将整个目录的文件转换字符编码的脚本
2012-06-18 20:47 3585源文件编码:gbk 源文件名称模式:*.ftl.gbk 目 ... -
Bash小技巧(惯用法)-2
2012-05-12 07:17 2158读取文件的第一行 很简单: head -1 file.tx ... -
Bash小技巧(惯用法)-1
2012-05-10 20:55 2578Bash小技巧(惯用法) 退出码判断(命令执行成功与否的判断 ... -
写一个Bash脚本来计算母亲节和父亲节的日期(推荐)
2012-05-10 20:31 2757写一个Bash脚本来计算母亲节和父亲节的日期 母亲节(每年 ... -
推荐Bash提高资料:写出健壮的Bash脚本
2012-03-20 13:58 3424写出健壮的Bash脚本 本文链接:http://coding ... -
在Linux下使用top命令查看所有java进程的状态
2011-10-28 11:09 9631在Linux下使用top命令查 ... -
导入MySQL数据库模式及数据的Bash脚本 (导出的姊妹篇)
2011-10-11 09:48 2779导入MySQL数据库模式及数据的Bash脚本 本文链接:ht ... -
导出MySQL数据库模式及数据的Bash脚本 真的很好用!
2011-10-10 10:14 3929导出MySQL数据库模式及数据的Bash脚本 本文链 ... -
导出MySQL数据库模式及数据的Bash脚本
2011-10-08 14:41 0导出MySQL数据库模式及数据的Bash脚本 ... -
AA制消费金额统计的Bash脚本
2011-09-02 19:57 2035AA制消费金额统计的Bash ... -
AA制消费金额统计的Bash脚本
2011-09-02 16:27 0AA制消费金额统计的Bash ... -
Bash字符串处理总结(与Java对比)
2011-08-26 22:02 0。 Bash字符串处理总结(与Java对比) ... -
Linux下实时跟踪log4j日志文件的bash脚本 - 增强了tail -f的功能
2010-11-05 13:08 7669Linux下实时跟踪log4j日志文件的bash脚本 - 增强 ... -
用Google AJAX Search API对互联网上Linux命令出现次数排名
2010-10-31 14:30 3172用Google AJAX Search API对互联网上Lin ... -
我使用过的Linux命令之history
2010-09-30 14:03 0我使用过的Linux命令之history 本文链接: ( ... -
我使用过的Linux命令之g++
2010-09-29 13:51 0我使用过的Linux命令之g++ 用途说明 常用参数 使 ... -
我使用过的Linux命令之gzip
2010-09-29 13:51 0我使用过的Linux命令之gzip 用途说明 常用参数 ... -
我使用过的Linux命令之gunzip
2010-09-29 13:50 0我使用过的Linux命令之gunzip 用途说明 常用参数 ... -
我使用过的Linux命令之groups
2010-09-29 13:50 0我使用过的Linux命令之groups 用途说明 常用参数 ... -
我使用过的Linux命令之groupmod
2010-09-29 13:49 0我使用过的Linux命令之groupmod 用途说明 常用 ...
相关推荐
cvs源代码管理工具cvs源代码管理工具cvs源代码管理工具cvs源代码管理工具cvs源代码管理工具cvs源代码管理工具
Linux下的cvs配置规则及细节问题。
cvs 将创建project_name目录,并将最新版本的源代码导出到相应目录中。这个checkout和Virvual SourceSafe中的check out不是一个概念,相对于Virvual SourceSafe的check out是cvs update, check in是cvs commit。
CVS操作日志统计,可按开发人员分别统计昨天、本周、上周、前12个月,以及全部时间内的修改行数(增加行数、删除行数)。统计结果生成html文件。 特别是可以统计出CVS文件第一个版本的行数。网上找不到类似工具(没...
cvs服务器端 eclipse+vss 源代码控制器 cvsnt2·5·03·2382代码控制.msi SourceSafe6.0 eclipse+vss配置.doc vss服务器管理说明文档.doc VSS序列号.txt
CVS的帮助手册,有linux下使用cvs的常用命令详细说明
Myeclipse+下配置CVS服务器源代码管理
CVS清空和设置批处理标本,Windows中为批处理脚本,Linux中为Shell脚本。 可用于快速清空目录中的CVS目录,或者设置CVS用户、IP和目录。 Clear all directory named CVS under given directory. Set the root of ...
附加1:为用户分配权限 附加2:加密密码 附件3:创建多个仓库 其他安装请见: 第一章Linux 下安装 JDK 第二章Linux 下安装 Tomcat5.5 第三章Linux 下安装 Mysql5.0 第四章Linux 下安装 ...
linux cvs 使用 多个关键字请用空格分隔,最多填写5个。点击右侧Tag快速添加
如何在红旗linux中构建cvs服务器
删除CVS目录bat脚本
linux安装cvs操作手册 需要安装cvs在LINUX上的请下载
是否感觉linux下使用cvs命令效率低下?这个linux下的图形化cvs工具可以帮助大大提高效率^^
本文档详细的介绍了在Linux下CVS服务器的配置
linux下CVS服务器端的安装与配置,wincvs的安装与配置
linux下教你如何配置CVS服务器,WORD文字形式,一看就很清楚是怎么配置了呵呵
包含四部分:Linux下cvs的创建、Linux下CVS的维护说明、CVSNT的维护说明、WINCVS常见问题处理。
linux 下 cvs 服务器 和客户端安装工具以及 安装文档