I learned how to remove prefix and suffix respectively as below:
p="prefix-foo-bar-suffix"
echo ${p#prefix} # -foo-bar-suffix
echo ${p%suffix} # prefix-foo-bar-
and I am trying to figure out how to remove them together based on the examples above. I tried the code below but it does not work.
echo ${p#prefix%suffix} # prefix-foo-bar-suffix, looks like it treats "prefix%suffix" as a whole thing
echo ${{p#prefix}%suffix} # error, bad substitution
P.S. I know it should be easy to make it work using regex, but here I want to know if it is possible to construct a solution that just builds on top of the # and % tricks. Also, using eval may make it very easy, but as some people suggest, I tend to avoid it here.