if [[ 6 > 50 ]]; then
echo "true"
fi
$ bash script.sh
I'm missing something very obvious here. Why is 6 greater than 50 ??
** EDIT **
I'm also try to solve for
if [[ 6.5 > 50 ]]; then
echo "true"
fi
if [[ 6 > 50 ]]; then
echo "true"
fi
$ bash script.sh
I'm missing something very obvious here. Why is 6 greater than 50 ??
** EDIT **
I'm also try to solve for
if [[ 6.5 > 50 ]]; then
echo "true"
fi
If you need to compare floats, the easiest way is to call out to an external tool like awk or bc
a=6.1
b=50
if [[ "$(echo "$a > $b" | bc)" -eq 1 ]]; then echo "a greater than b"; fi
If you're comparing integers then use
if [[ 6 -gt 50 ]]; then echo "true"; fi
otherwise since bash cannot handle floating point
if (( $(echo "6.5 > 50" | bc -l) )); then echo "true"; fi
You supplied [[ args ]]
which is a conditional expression, when you meant to perform arithmetic evaluation which uses the (( condition ))
syntax.
syntax error: invalid arithmetic operator (error token is ".00 > 50 ")
– Jacksonkr
Sep 09 '20 at 01:21
man bash
.
– John1024
Sep 09 '20 at 01:21
man bash
: "When used with [[, the < and > operators sort lexicographically using the current locale." – steeldriver Sep 09 '20 at 01:06