递归添加特定源文件类型到svn
我知道这是一个丑陋的脚本,但它完成了工作。 我现在面临的是添加更多的扩展,这会使票据更加混乱。 我怎样才能让它更加模块化? 具体来说,如何在多行上编写这么长的正则表达式(源文件扩展名)?每行说一个分机号。我想我在字符串连接方面做错了什么,但不太确定到底是什么。 这是原始文件:
#!/bin/bash
COMMAND='svn status'
XARGS='xargs'
SVN='svn add'
$COMMAND | grep -E '(\.m|\.mat|\.java|\.js|\.php|\.cpp|\.h|\.c|\.py|\.hs|\.pl|\.xml|\.html|\.sh|.\asm|\.s|\.tex|\.bib|.\Makefile|.\jpg|.\gif|.\png|.\css)'$ | awk ' { print$2 } ' | $XARGS $SVN
这大致是我的目标
...code code
'(.\m|
\.mat|
\.js|
.
.
.
.\css)'
..more code here
有人吗?
I know this is an ugly script but it does the job.
What I am facing now is adding a few more extensions what would clutter the scrip even more.
How can I make it more modular?
Specifically, how can I write this long regular expression (source file extensions) on multiple lines? say one extension on each line. I guess I am doing something wrong with string concatenation but not quite sure what exactly.
Here's the original file:
#!/bin/bash
COMMAND='svn status'
XARGS='xargs'
SVN='svn add'
$COMMAND | grep -E '(\.m|\.mat|\.java|\.js|\.php|\.cpp|\.h|\.c|\.py|\.hs|\.pl|\.xml|\.html|\.sh|.\asm|\.s|\.tex|\.bib|.\Makefile|.\jpg|.\gif|.\png|.\css)'$ | awk ' { print$2 } ' | $XARGS $SVN
and here's roughly what I am aiming at
...code code
'(.\m|
\.mat|
\.js|
.
.
.
.\css)'
..more code here
Anybody?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我知道这并不能直接回答问题,但从可读性的角度来看,我认为大多数开发人员都会同意单行正则表达式是最常见的处理方式,因此也是最可维护的方法。此外,我不确定为什么您在每个扩展中都包含一个句点,这应该只需要使用一次。
我写了这个小脚本来自动将所有图像添加到 svn。您应该能够简单地在正则表达式中的管道之间添加扩展名来添加或删除不同的文件类型。请注意,它通过确保每行以“?”开头来确保仅添加无法识别的文件。 (^\?) 并以句点 (\.(extensions)$) 结尾。希望它有帮助!
I know this doesn't answer the question directly, but from a readability perspective, I think most developers would agree that a single-line regex is the most common way to do things and therefore the most maintainable approach. Further, I'm not sure why you're including a period in each of your extensions, this should only need to be used once.
I wrote this little script to automatically add all images to svn. You should be able to simply add extensions between the pipes in the regex to add or remove different file types. Note that it makes sure to only add files that are unrecognized by making sure each line starts with a "?" (^\?) and ends with a period (\.(extensions)$). Hope it's helpful!
怎么样:(
请注意,如果您在调用 echo 时在 $PATTERNS 周围加上引号,这将不起作用 - echo 正在为我们负责剥离空格并将换行符转换为空格。)
How about this:
(Note that this would not work if you put quotes around $PATTERNS in the call to echo -- echo is taking care of stripping whitespace and converting newlines to spaces for us.)