获取字符串开头的最长非全局字符串
我正在尝试创建一个脚本来从 $GIT_DIR/info/exclude 转换为 .gitignore 文件。我想将 .gitignore 文件尽可能靠近模式目标,这意味着像 /a/b/*/*.c
这样的 glob 应该放在 /a 中/b/.gitignore
。为了准确地做到这一点,我需要一些可以基于 man glob
唯一标识的从头返回最长子字符串的东西。是否存在这样的东西,最好是可以跨 *nixes 移植的东西?
I'm trying to create a script to convert from $GIT_DIR/info/exclude to .gitignore files. I'd like to put the .gitignore files as close to the pattern target as possible, meaning that a glob like /a/b/*/*.c
should be put in /a/b/.gitignore
. To do this accurately, I need something which can return the longest substring from the start which is uniquely identified, based on man glob
. Does there exist anything like this, preferably something which is portable across *nixes?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
找到了解决方案 - 通过迭代
dirname "$string"
直到[ -e "$string" ]
成功。生成的脚本可以在 博客文章。Found a solution - By iterating over
dirname "$string"
until[ -e "$string" ]
succeeds. The resulting script can be found in a blog post.