I am trying to perform a simple integer comparison in bash, which I am new to using, and my methods are causing an error. Any advice would be appreciated.
My basic logic is that I am reading in hurricane track points. There may be multiple entries for the same track_id, with different pressure values. What I want to do is store only one entry per track_id into the array track_id_poly; the case with the lowest pressure. So I am looping through each line, and attempting to compare the current pressure (for $int), with the previous track pressure ($int - 1), and if it is lower, replace the previous array value with the new lower pressure. I hope that makes sense. My code is below.
int=0
while read track_id ppres_inter
do
printf -v pres_inter "%.0f" "$pres_inter"
echo pressure $pres_inter
case $int in
0)
Track_id_poly[$int]=$track_id
Pres_inter_poly[$int]=$pres_inter
((int=int+1)) ;;
*)
if [[ $track_id == ${Track_id_poly[$int-1]} ]]
then
if (( $pres_inter -lt ${Pres_inter_poly[$int-1]} ))
then
Track_id_poly[$int-1]=$track_id
Pres_inter_poly[$int-1]=$pres_inter
fi
else
Track_id_poly[$int]=$track_id
Pres_inter_poly[$int]=$pres_inter
((int=int+1))
fi ;;
esac
done <$file_poly
int_poly=$int
echo Number of polygon crossings from set $i is $int_poly
The line that is causing me problems is the integer comparison for $pres_inter.
if (( $pres_inter -lt ${Pres_inter_poly[$int-1]} ))
I get the following error:
line 41: 96800 -lt 98759 : syntax error in expression (error token is "98759 ")
Any tips to fix this problem would be appreciated. Probably a simple fix!