View Full Version : [SOLVED] Bash: Please explain ${var##*.}

September 5th, 2011, 10:38 AM
I'm using bash to find the last part of a string e.g. 'myfile.3' - I found a method which works, but I don't know why!

What should I be googling to find out more about this? reg exp or something else?

The code;

echo $(( ${var##*.} + 1 ))

That returns '46', which is correct (i.e. 45+1) - What I need to understand is the var##*. piece. How is that saying 'go to the end of the string, the part after the '.', and return that'

September 5th, 2011, 10:59 AM
Look at the bottom of this page, it explains it very well.


In order to answer your question about what you should be searching for it's called parameter expansion.

September 5th, 2011, 11:07 AM
Nice link, thanks for the reply!

September 5th, 2011, 11:16 AM
No problem. Read the FAQs and bash pitfalls sections as well when you have time.:)