jhonan
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;
var=my.test.file.23.45
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'
What should I be googling to find out more about this? reg exp or something else?
The code;
var=my.test.file.23.45
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'