bashshell

Compare variable with integer in shell?


I have an if statement I need to run, as long as the value I have stored in my $counter variable is greater than 5.

Here is the respective section of my current (non-functioning) script:

if $counter > 5
then
    echo "something"
fi

The mistake I'm making is probably very obvious, but for some reason I couldn't find the solution online.. Thanks!


Solution

  • Well that is quite simple:

    if [ "$counter" -gt 5 ]
    then
        echo "something"
    fi