shell脚本有趣!如何对给定路径的每个子目录执行操作?
我正在编写一个 shell 脚本(我很不擅长),我需要一些帮助。它是一个将东西从 git 转移到 CVS 的脚本(不重要)。问题是,ia 文件路径:
controllers/listbuilder/setup/SubmissionRolesListbuilderHandler.inc.php
我需要能够做到:
cvs add controllers;
cvs add controllers/listbuilder;
cvs add controllers/listbuilder/setup;
cvs add controllers/listbuilder/setup/SubmissionRolesListbuilderHandler.inc.php
有人可以帮助我吗?到目前为止,我想到的最好的方法是递归地添加工作树中的所有文件,但这似乎效率很低。
编辑:我被要求澄清。这里是:我希望能够在给定文件路径列表的情况下 CVS ADD 文件,并在必要时以某种方式处理新文件夹的添加。
I am writing a shell script (which I suck at) and I need some help. Its a script that is moving things from git to CVS (not important). The thing is, i a file path:
controllers/listbuilder/setup/SubmissionRolesListbuilderHandler.inc.php
and I need to be able to do:
cvs add controllers;
cvs add controllers/listbuilder;
cvs add controllers/listbuilder/setup;
cvs add controllers/listbuilder/setup/SubmissionRolesListbuilderHandler.inc.php
Can someone help me out? The best I've come up with so far is to recursively add ALL files in my working tree, but that seems overly inefficient.
EDIT: I was asked for clarification. Here goes: I want to be able to CVS ADD files, given a list of file paths, and somehow handle the addition of new folders when necessary.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
添加所有目录:
添加所有文件:
我不确定你真正想要实现什么。
Add all directories:
Add all files:
I'm not sure what you really want to achieve.
这有点杂乱无章,如果你把它看得太脏的话,毫无疑问会失败,但是:
这个脚本更多的是一个想法,而不是一个完整的解决方案。例如,如果您需要完整的相对路径(而不仅仅是目录名称),则可以使用
cut -d/ -f1-$i
计算斜杠的数量。This is somewhat kluge-ish, and will no doubt fail if you give it a dirty look, but:
This script is more of an idea than a complete solution. For example, if you need the full relative path (not just dir name), you could count up to the number of slashes, using
cut -d/ -f1-$i
.