1

I tried:

if [[ ${numbers[4]} -ge $best_res ]]; then
                             ...
fi 

I got the following error for the if condition line:

7 ./q1.sh: line 58: [[: 0.346: syntax error: invalid arithmetic operator (error token is ".346")

there are similar questions, but my error is in "if" condition. How can I fix it with "bc" or "dc"?

Ahmad
  • 8,811
  • 11
  • 76
  • 141

1 Answers1

2

The problem is that bash doesn't support floating point arithmetic, which is what one of your variables appears to have.

Here's simple example:

$ [[ 0.346 -ge 0 ]] && echo "true"
bash: [[: 0.346: syntax error: invalid arithmetic operator (error token is ".346")

You'll have to use external tools like bc or dc, etc.

P.P
  • 117,907
  • 20
  • 175
  • 238