It's a bit of a contrived example but here goes:
Say I have a variable 1.2.3.4
containing version information and need to replace the .4
at the end with .5
version=1.2.3.4
echo ${version%.*}.5
1.2.3.5 #no problem
But when I attempt to "in-line" the substitution with /
and a %
anchor
echo ${version/%.*/.5}
1.5
Bash does a greedy substitution. Is there a way to have bash take the substitution up "non-greedily" so I can use substitution as a replacement for the earlier delete+append approach?
Best Answer
Not in general but easily in this case: