您好,我正在嘗試在Ubuntu shell中創建一個程序,並在輸入變量後程序崩潰。代碼如下:http://pastebin.com/Chu4DPgFUbuntu Shell腳本問題
#!/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
我不知道什麼是錯的代碼。我相信它有一個基本問題。提前致謝。
您需要在問題中包含您的代碼。 (順便說一句,我抓起了你的腳本的一個副本,它對我來說很好。) –
你輸入了什麼,錯誤信息是什麼? –
我爲所有成績輸入了10,並且在輸入第4個字符後我立即崩潰 – BigShovel