0

I am trying to execute the following code in a bash script to determine whether or not a number is greater than 1 or less than 1.

Bash Code:

weight_check=`bc <<< "(.4+.4+.1+.1+.2)"`
if [[ ${weight_check} -lt "1.0" ]] || [[ ${weight_check} -gt "1.0" ]];
then
    echo "Incorrect Weights!"
    exit 0
fi

Error:

syntax error: invalid arithmetic operator (error token is ".2")

The sum of ${weight_check} equals 1.2 but, the bash script doesn't see this...

The input numbers in ${weight_check} will change so, I need this if/then/fi statement to be able to act dynamically.

Is my if/then/fi statement set up incorrectly?

Aaron Perry
  • 931
  • 1
  • 10
  • 32

0 Answers0