Point flottant sous UNIX avec bash Shell

S’il vous plaît aidez-moi à découvrir cela, je suis très nouveau à UNIX, mon code est vraiment ne peut pas obtenir la bonne réponse …

#! /usr/bin/env bash echo -n "How many number : "; read num for ((i=0; i<$num; i++)); do echo -n "Enter your number : "; read number total+=$(echo "${number}" | bc) echo "${total}" done 

 echo -n "Enter your numbers: " read numbers total=$(echo "$numbers" | sed 's/ \+/ + /g' | bc) echo "The total is $total" 

Exemple d’utilisation:

 Enter your numbers: 4 6 2.47 The total is 12.47 

MORE: Dans votre script, le problème était que le total+=$(echo "${number}" | bc) la ligne total+=$(echo "${number}" | bc) . Cela le corrige:

 #! /usr/bin/env bash total=0 echo -n "How many number : "; read num for ((i=0; i<$num; i++)); do echo -n "Enter your number : "; read number total=$(echo "$total + ${number}" | bc) echo "${total}" done