(standard_in) 1: erro de análise com comparação de decimais

0

Continuo com um erro de análise e tentei verificar o código, mas não consigo ver o que poderia estar errado?

#!/bin/bash
echo -n "Please enter first: "
read first
echo -n "Please enter second: "
read second
echo -n "Please enter third: "
read third
si=$(echo "scale=4; $first/$second"| bc -l)
il=$(echo "scale=4; $second/$third"| bc -l)
six=$(echo "scale=4; 0.66/1"| bc -l)

if (( $(echo "scale=4; $si -gt $six" | bc -l) )) && (( $(echo "scale=4; $il -gt $six" | bc -l) ))
    then
    echo "Value is a"
    elif (( $(echo "scale=4; $si -lt $six" | bc -l) ))
    then
    echo "Value is b"
    elif (( $(echo "scale=4; $il -lt $six" | bc -l) ))
then
    echo "Value is c"
else
    echo "Value is d"
fi
    
por Lin Ni Huang 12.05.2016 / 04:33

1 resposta

0

Você está usando os scripts -lt e -gt in bc , mas estes não são operadores em bc . Substitua todas as ocorrências de -lt e -gt por < e > , respectivamente.

if (( $(echo "scale=4; $si > $six" | bc -l) )) && (( $(echo "scale=4; $il > $six" | bc -l) ))
    then
    echo "Value is a"
    elif (( $(echo "scale=4; $si < $six" | bc -l) ))
    then
    echo "Value is b"
    elif (( $(echo "scale=4; $il < $six" | bc -l) ))
then
    echo "Value is c"
else
    echo "Value is d"
fi

Além disso, a primeira condição pode ser combinada usando um único bc :

if (( $(echo "scale=4; $si > $six && $il > $six" | bc -l) ))
    
por janos 21.12.2016 / 23:38