I am trying to use bc to compare a value with decimals in my if statement. I am not sure if I am using bc correctly in my if statement because it doesn't seem to work. It always enters the 4th if statement "IF4". It doesn't seem like the other conditions are being read properly?
#SET INITIAL SPEED
initialspeed() {
wpm=0
echo wpm: $wpm
#CHECKS IF SPEED WAS GIVEN
if [ -z "$wpm" ]
then
let wpm=0.6
echo IF1 wpm: $wpm #DEBUG
#CHECK IF SPEED IS VALID
elif [ 'echo "if$($wpm > 0.6)1;if$($wpm<=0.6)0" | bc' = 1 ]
then
echo IF2 wpm: $wpm #DEBUG
echo Error speed is less than 100 wpm
exit 3
elif [ 'echo "if$($wpm < 0.06)1;if$($wpm<=0.06)0" | bc' = 1 ]
then
echo IF3 wpm: $wpm #DEBUG
echo Error speed is more than 1000 wpm
exit 3
else
wpm=$(echo "scale=2;60/$2 | bc")
echo IF4 wpm: $wpm #DEBUG
fi
}
Aucun commentaire:
Enregistrer un commentaire