Alternative form of long prefix/suffix removal (#1941)

The ${foo/%from} is an alternative form of the long suffix removal.
Likewise, he ${foo/#from} is an alternative form of the long prefix removal.

Test cases:

~~~bash
foo=gododa

# The following are the same: Long prefix removal.
# Result: r=a
r=${foo/#g*d}
r=${foo##g*d}
# (Compare to short prefix removal)
# Result: r=oda
r=${foo#g*d}

foo=agogod

# The following are the same: Long suffix removal.
# Result: r=a
r=${foo/%g*d}
r=${foo%%g*d}
# (Compare to short suffix removal)
# Result: r=ago
r=${foo%g*d}
~~~
This commit is contained in:
Dan Nissenbaum 2023-01-31 03:55:15 -05:00 committed by GitHub
parent 5efbf15d4f
commit b91885ec71
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 0 deletions

View File

@ -187,7 +187,9 @@ dir=${src%$base} #=> "/path/to/" (dirpath)
| `${foo#prefix}` | Remove prefix |
| --- | --- |
| `${foo%%suffix}` | Remove long suffix |
| `${foo/%suffix}` | Remove long suffix |
| `${foo##prefix}` | Remove long prefix |
| `${foo/#prefix}` | Remove long prefix |
| --- | --- |
| `${foo/from/to}` | Replace first match |
| `${foo//from/to}` | Replace all |