ThePretender73 ThePretender73 - 5 months ago 9
Bash Question

Arithmetic statements in bash if clause

Just a quick question about the above stated topic:

I'm currently trying to use a value i am given through read in my if statement:

if [ $value1 -lt $value2 -a $value1 is -ge $value2/2 ]


How is it possible to compare one value to half of another without having to make an equation beforehand?

Answer

Use Bash arithmetic:

if (( value1<value2 && value1>=value2/2 )); then