I am trying to compare two decimal values but I am getting errors. I used
if [ \"$(echo $result1 \'>\' $result2 | bc -l)\" -eq 1 ];then
You can also echo
an if...else
statement to bc
.
- echo $result1 '>' $result2
+ echo "if (${result1} > ${result2}) 1 else 0"
(
#export IFS=2 # example why quoting is important
result1="2.3"
result2="1.7"
if [ "$(echo $result1 '>' $result2 | bc -l)" -eq 1 ]; then echo yes; else echo no;fi
if [ "$(echo "if (${result1} > ${result2}) 1 else 0" | bc -l)" -eq 1 ];then echo yes; else echo no; fi
if echo $result1 $result2 | awk '{exit !( $1 > $2)}'; then echo yes; else echo no; fi
)