Compare float value with single decimal

#!/bin/bash
filter_file=/export/home/alvin/test.txt
range1_count=0
range2_count=0
categorized(){
	value=$1
	if [$value -ge 5.1 && $value -le 10.0] # range 5.1 to 10.0
	then
		range1_count=`expr $range1+ 1`
	elif [$value -ge 10.1 && $value -le 15.0] # range 5.1 to 15.00
	then
		range2_count=`expr $range2+ 1`
	fi
}

#read txt file which contain lines of float with single decimal
loop_function(){
	while read line
	do
		categorized $line
	done < $filter_file
}

loop function

I got an issue about comparing two floating point with single decimal, by right -le and -ge is for integer value. So, what should i do?

show you an example, it might help you

if [[ $(echo "6.5 > 4.5" | bc) == 1 ]]; then echo ok; fi
ok
#!/bin/bash

declare $(awk '$1>=5.1 && $1<=10{r1++}$1>=10 && $1<=15{r2++}END{print "range1_count="r1,"range2_count="r2}' /export/home/alvin/test.txt)

May i know how to get the range1_count and range2_count?

I used

#!/bin/bash
declare $(awk '$1>=5.1 && $1<=10{r1++}$1>=10 && $1<=15{r2++}END{print "range1_count="r1,"range2_count="r2}' /export/home/alvin/test.txt)
echo range1_count
echo range2_count

output:

projadm@/alvin% ./count_v2.sh

projadm@/alvin% 

No value display, may i know why?

Yes :wink:

haha~~ i always forgot this $ symbol..
Thanks , it works.
I am newbie in shell scripting, would you please to explain the method declare is what about ?

You could work with the value * 10 eg:

value=$(echo "scale=0;$1*10/1" | bc)
if [ $value -ge 51 && $value -le 100] # range 5.1 to 10.0

whats up, its a useful ideas. it really help me thanks.

declare is a bultin shell command , see man bash ("bash") manual for reference.
Using awk we make only one system call, process the dataset and return the results(variable) to shell versus running the test and calling bc for each data record.