无法让它运行。我确定我做错了什么,我确定我忽略了一些东西。
a=3
echo "Type in the first Grade Number."
read num1;
echo "Type in the Second Grade Number."
read num2;
echo "Type in the third Grade Number."
read num3;
echo \($num1 + $num2 + $num3\)/$a | bc
read num;
if [ $num-lt 79 ]
then
echo "The Grade Number is an C."
elif [ $num-lt 89 ]
then
echo "The grade number is an B."
elif [ $num-lt 99 ]
then
echo "Your grade number is an A."
elif [ $num-lt 60 ]
then
echo "You have a failing number"
fi
答案 0 :(得分:1)
if [ $num-lt 79 ]
您需要 $num
和-lt
之间的空格。没有它,它就是两个论证的表达形式。根据{{1}}手册页,因此评估双参数形式:
如果第一个参数是
bash
,则当且仅当第二个参数为null时,表达式才为真。如果第一个参数是上面在CONDITIONAL EXPRESSIONS下列出的一元条件运算符之一,则如果一元测试为真,则表达式为true。 如果第一个参数不是有效的一元条件运算符,则表达式为false。
您的脚本还有一些其他问题,您也可以查看。
首先,!
语句末尾不需要;
个字符。它们没有破坏性,但它们是多余的。
其次,您似乎输出三个等级的平均值,然后要求另一个检查等级的数字。我原以为平均值本身就是一个更好的衡量标准:
read
第三,你的逻辑意味着永远不会输出失败等级。小于num=$(echo "($num1 + $num2 + $num3) / $a" | bc)
的初始测试已经捕获了小于60
的数字。更好的方法是按顺序检查边界,例如:
79