I'm trying to match a version number from a string in the format 4.6, or 2.8. I have the following which I will eventually use in a function in my .bashrc file to find the OS version:
function test () {
string="abc ABC12 123 3.4 def";
echo `expr match "$string" '[0-9][.][0-9]'`
}
However, this doesn't match the 3.4 in the string. Can anyone point me in the right direction here?
Thanks.
[0-9]\.[0-9][.]any single character? Does your function match anything at all? I don't know the specifics of regex in bash, but I would assume the match would be something like "2 1".expr match STRING REGEXreturns 0 if there's a match, nonzero otherwise. This is what happens with your example on my machine.