ThePretender73 ThePretender73 - 1 year ago 101
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 Source

Use Bash arithmetic:

if (( value1<value2 && value1>=value2/2 )); then
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download