开发者

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

开发者 https://www.devze.com 2022-12-11 05:56 出处:网络
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/

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

精彩评论

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