Quote:
|
Originally Posted by indo1144
Found it! I wanted to read more about this, but did not realize this was a shell built-in option, so did not think of man bash (in my case)...
|
I believe I understand what happened...
Quote:
${parameter##word}
The word is expanded to produce a pattern just as in pathname expansion. If the pattern matches the
beginning of the value of parameter, then the result of the expansion is the expanded value of parameter
with the shortest matching pattern (the ``#'' case) or the longest matching pattern (the ``##'' case)
deleted. If parameter is @ or *, the pattern removal operation is applied to each positional parameter
in turn, and the expansion is the resultant list. If parameter is an array variable subscripted with @
or *, the pattern removal operation is applied to each member of the array in turn, and the expansion is
the resultant list.
|
So the ##-case expands to the longest matching pattern deletion. Since the parameter is *, it removes all matching patterns in the array, until it has no matches left. You read in the entire pathname as an array which has a delimiter "/" and the final result is the filename only.
Am I right?
This would mean that /foo/bar/filename.pdf would result in filename.pdf, but if the input would have a trailing slash like so: /foo/bar/files/ it would return... nothing!