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.
精彩评论