thank you thank you - 17 days ago 6
Bash Question

bash scripting if statement, comparing decimal

Kind of new to bash scripting and is having trouble with the below code.
I am trying to compare the array number with the number you have input from the "read ans" the problem is mostly comparing decimal numbers

BGpercent=(0 99 99.3 99.6 99.8 100)
BGpoint=(0 1 2 3 4 5)
read ans
for (( c=${#BGpercent[@]}; c>=0; c-- ))
do
echo "${BGpercent[$c]}"
if [ "${BGpercent[$c]}" <= "$ans" ];
then
result=${BGpoint[$c]}
break
fi
done
echo $result | bc -lstrong text


Error - ./testscript.sh: =: No such file or directory

Answer

BGpercent=(0 99 99.3 99.6 99.8 100) BGpoint=(0 1 2 3 4 5)

echo " Write in your number:" read number

for (( c=${#BGpercent[@]}-1; c>-1; c-- )) do echo ${BGpercent[$c]} bool=echo "if (${BGpercent[$c]} <= ${number}) 1" | bc if [ "$bool"1 -eq 11 ] ; then result=${BGpoint[$c]} break fi

Comments