I'm having some trouble with float array.
When i try to get the array sum with float numbers i get this error line 39: soma + 2.34 | bc: syntax error: invalid arithmetic operator (error token is ".34 | bc")
26 Somar() {
27 echo "Quantos numeros deseja somar?"
28 read numeros
29 vetorSoma[$numeros]=" "
30 for (( i=0;i<$numeros;i++ ))
31 do
32 con=$((con+1))
33 echo -n "digite o $con� numero: "
34 read vetorSoma[$i]
35 done
36
37 for i in ${vetorSoma[@]}; do
38 sum=0
39 soma=$((soma + $i | bc))
40 done
41 echo "O resultado foi $soma"
42 }
when i type int numbers it works great, i just don't know why.
Thx.
You need to printf / echo a string including your numbers and the arithmetic operation (+ possibly other bc commands like "scale") and pipe that to bc .