From b91885ec71c820bbbdcafec3eb1c78ff498cfd12 Mon Sep 17 00:00:00 2001 From: Dan Nissenbaum Date: Tue, 31 Jan 2023 03:55:15 -0500 Subject: [PATCH] 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} ~~~ --- bash.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bash.md b/bash.md index 66afe4b77..98d480765 100644 --- a/bash.md +++ b/bash.md @@ -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 |