(standard_in)1:比较小数时解析错误

(standard_in)1:比较小数时解析错误

我一直收到解析错误,并试图检查代码,但我看不出是什么问题?

#!/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

答案1

您在脚本中使用了-lt和,但这些不是 中的运算符。请分别将所有出现的和替换为和。-gtbcbc-lt-gt<>

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

此外,第一个条件可以用一个来组合bc

if (( $(echo "scale=4; $si > $six && $il > $six" | bc -l) ))

相关内容