开发者

Get the longest non-glob string at the start of a string

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 uniqu开发者_StackOverflowely identified, based on man glob. Does there exist anything like this, preferably something which is portable across *nixes?


Found a solution - By iterating over dirname "$string" until [ -e "$string" ] succeeds. The resulting script can be found in a blog post.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜