您好我正在尝试在Ubuntu shell中创建一个程序,并且在输入变量后程序崩溃了。代码如下:http://pastebin.com/Chu4DPgF
#!/bin/bash
echo -n "Enter assignment mark:"
read assign
echo -n "Enter Test 1 mark:"
read test1
echo -n "Enter Test 2 mark:"
read test2
echo -n "Enter Final Exam mark:"
read final
total=$(($assign + $test1 + $test2 + $final))
if [[ $total -ge 90 && $total -le 100 ]]; then
echo "Your grade is A+"
elif [[ $total -ge 85 && $total -le 89 ]]; then
echo "Your grade is A"
elif [[ $total -ge 80 && $total -le 84 ]]; then
echo "Your grade is A-";
elif [[ $total -ge 77 && $total -le 79 ]]; then
echo "Your grade is B+"
elif [[ $total -ge 73 && $total -le 76 ]]; then
echo "Your grade is B"
elif [[ $total -ge 70 && $total -le 72 ]]; then
echo "Your grade is B-"
elif [[ $total -ge 67 && $total -le 69 ]]; then
echo "Your grade is C+"
elif [[ $total -ge 63 && $total -le 66 ]]; then
echo "Your grade is C"
elif [[ $total -ge 60 && $total -le 62 ]]; then
echo "Your grade is C-"
elif [[ $total -ge 57 && $total -le 59 ]]; then
echo "Your grade is D+"
elif [[ $total -ge 53 && $total -le 56 ]]; then
echo "Your grade is D"
elif [[ $total -ge 50 && $total -le 52 ]]; then
echo "Your grade is D-"
elif [[ $total -ge 0 && $total -le 49 ]]; then
echo "Your grade is F"
else
echo "?"
fi
我不知道代码有什么问题。我确信它存在根本问题。提前谢谢。
答案 0 :(得分:-1)
将第15行更改为
((total = assign + test1 + test2 + final))
以及此格式的以下所有行:
if [[ $total -ge 90 && $total -le 100 ]]; then
echo "Your grade is A+"
到
if [ $total -ge 90 ] && [ $total -le 100 ]; then
echo "Your grade is A+"
它应该有效。 与白色空格完全相同