My calculator generates the error mentioned in the title when I try to use the operator "/" as well as the numbers 4.5 and 2.
This is (just like the error states) most likely due to what's after the decimal point in 4.5, but I don't know how I could fix this and why the script actually manages to give me the correct result afterwards.
Code:
#!/bin/bash
read -p "Operator: " operator
read -p "First number: " ch1
read -p "Second number: " ch2
case $operator in
"+") echo "scale=2; $ch1+$ch2" | bc -l;;
"/") if [[ $ch1 -eq 0 || $ch2 -eq 0 ]]
then
echo "Nope..."
else
echo "scale=2; $ch1/$ch2" | bc -l
fi
;;
esac
Full output:
./script2.sh: line 9: [[: 4.5: syntax error: invalid arithmetic operator (error token is ".5")
2.25