s to a number less than zero counts back from the end of the expanded value of $param.
When a negativ... ${variable%pattern}
If the pattern matches the end of the variable's value, delete the shortest part... ${variable%%pattern}
If the pattern matches the end of the variable's value, delete the longest part ... s the "too simple to be worth a separate program" end of simplicity.
Naturally you can call on sed, aw