1

This question already has an answer here:

I know how to use

${parameter#word} Remove matching prefix pattern

and

${parameter%word} Remove matching suffix pattern.

but is there a way to nest them in a single call, such as

${${variable#foo}%bar}

?

It looks like I should be able to use this somehow

If the first character of parameter is an exclamation point (!), a level of variable indirection is introduced. Bash uses the value of the variable formed from the rest of parameter as the name of the variable; this variable is then expanded and that value is used in the rest of the substitution, rather than the value of parameter itself.

but I can't figure it out.

marked as duplicate by Gilles bash Jan 6 '16 at 17:32

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    You can't combine indirection with removals. In indirection, there are two variables involved, one containing the name of the other. In removals, there are two strings involved, but only one variable. – choroba Nov 6 '15 at 15:43