Search code examples
unixif-statementcomparisonuname

How to compare variable to text in unix


I've tried many version of this but none of them work.I want to compare variable - here it'll be version of os, with some string. I want to check if it is bigger than indicated version. When I pass exact name it is just fine, but when I want to replace something with .* it doesn't work.

if [[ "$(uname -r)" == '3\.18.*' ]];

then echo bravo;

fi

how to make it work? thanks in advance


Solution

  • I would use a case statement here:

    case $(uname -r) in
    (3.18.*) echo bravo;;
    esac
    

    If you want to check if the version is larger than some value or not, you might use something like:

    case $(uname -r) in
    (3.1[89].*|3.[2-9]*|[4-9]*) echo bravo;;
    (*) echo alpha;;
    esac