Just what it says. I'm trying to write a simple bash script from a question in a book. I'm trying to use the case statement, and for all I can tell I am using it correctly. However I keep getting "syntax error near unexpected token '$'in\r' case $i in.
No idea why. I'm also sure there are other problems in my code since this is my first script. The case statement is on line 10. Feel free to correct anything else, the end program will be building a grade data file for student grades, using a simple awk script to compute the average of the grades, and putting everything in the output file.
function getStudentData () {
i=0
while [ $i<5 ]
do
case $i in
[0]) echo -n "Enter student name\n"
read name
;;
[1]) echo -n "Enter Quiz grade\n"
read quiz
checkLimits $quiz
;;
[2]) echo -n "Enter homework grade\n"
read hw
checkLimits $hw
;;
[3]) echo -n "Enter midterm grade\n"
read midterm
checkLimits $midterm
;;
[4]) echo -n "Enter Final grade \n"
read final
checkLimits $final
;;
esac
done
}
function checkLimits ($grade) {
if [ grade <= 100 || grade >= 0 ]; then
$i--
fi
}
if [ $# -lt 2 ]; then
echo "Incorrect number of arguments"
exit 1
fi
#Check awk existance
if [ ! -e $2 ]; then
echo "Error, .awk file does not exist"
exit 1
fi
#flag for data file existing, and awk file
flag=0
#Check for data file existing
if [ ! -e $1 ];then
flag=0
else
flag=1
fi
ans="yes"
while [ $ans == "yes" || $ans == "y" ]
do
echo "Do you want to enter a student record?"
read ans
if [ $ans == "y" || $ans == "yes" ];then
getStudentData
else
echo "we done"
exit 1
fi
done