I have string=substr1-substr2-substr3.substr4 where the substrings are of variable length. I want to extract substr3 from string and am thinking of doing it using the ${string##pattern} and ${string%pattern} string manipulation expansions. Using this approach, it's clear I need to run ${string##*-} and run ${string%.*} on the resulting expansion, or vice versa. My questions are:
- is this the best choice?
- If yes, how do i run both in a single step? When I try to do something like
${string##*-${string%.*}}or${string%.*${string##*-}}I just get back the full string. I realize i could always do the extraction in two steps by assigning an intermediate variable to the result of the first step, and then manipulating that; but I want to do it in one step. How do I go about it?
TIA!