Use arithmetic (( ... ))
for conditions
You could replace:
if [ $i -gt 5 ] ; then
echo Do something with i greater than 5
fi
by
if((i>5));then
echo Do something with i greater than 5
fi
(Note: There is no space after if
)
or even
((i>5))&&{
echo Do something with i greater than 5
}
... or if only one command
((i>5))&&echo Echo or do something with i greater than 5
Further: Hide variable setting in arithmetic construct:
((i>5?c=1:0))&&echo Nothing relevant there...
# ...
((c))&&echo Doing something else if i was greater than 5
or same
((c=i>5?c=0,1:0))&&echo Nothing relevant there...
# ...
((c))&&echo Doing something else if i was greater than 5
... where if i > 5, then c = 1 (not 0;)