From 1a389039f89bf93454919ca9a0f8107cd0fd1ce6 Mon Sep 17 00:00:00 2001 From: Jack-Benny Persson Date: Sat, 14 Dec 2013 23:34:14 +0100 Subject: [PATCH] =?UTF-8?q?Betygs=C3=A4ttarskriptet=20klart?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Labb5/form.txt | 35 +++++++++++++++++++++++++++++ Labb5/ovning4.sh | 57 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 Labb5/form.txt create mode 100755 Labb5/ovning4.sh diff --git a/Labb5/form.txt b/Labb5/form.txt new file mode 100644 index 0000000..cd49868 --- /dev/null +++ b/Labb5/form.txt @@ -0,0 +1,35 @@ +Points Question +------ -------- +1 Question 1 +2 Question 2 +1 Question 3 +1 Question 4 +0 Question 5 +1 Question 6 +0 Question 7 +1 Question 8 +1 Question 9 +2 Question 10 +1 Question 11 +1 Question 12 +5 Question 13 +1 Question 14 +1 Question 15 +2 Question 16 +1 Question 17 +1 Question 18 +1 Question 19 +4 Question 21 +1 Question 22 +1 Question 23 +1 Question 24 +0 Question 25 +1 Question 26 +1 Question 27 +1 Question 28 +4 Question 29 +4 Question 30 +1 Question 31 +4 Question 32 +1 Question 34 +1 Question 35 diff --git a/Labb5/ovning4.sh b/Labb5/ovning4.sh new file mode 100755 index 0000000..9068408 --- /dev/null +++ b/Labb5/ovning4.sh @@ -0,0 +1,57 @@ +#!/bin/bash + +# Jack-Benny Persson +# LX13 +# Övning 4, labb 5 +# Grade-calculation script + +# Set some variables +G=30 +VG=48 +Form=form.txt + +# Check if the file exist and that we can read it +if [ ! -r $Form ]; then + echo "Can't read $Form" > /dev/stderr + exit 2 +fi + +# Get all the points +Points=( `tail -n +3 $Form | awk '{print $1}'` ) + +# Check that we only have int's in our array and print help +for l in ${Points[*]}; do + if ! [ "$l" -eq "$l" &> /dev/null ]; then + cat <<- EOF + Something is wrong with the formatting of $Form + Correct formatting should look like this: + + Points Question + ------ -------- + 1 Question 1 + 1 Question 2 + 4 Question 4 + + EOF + exit 2 + fi +done + +# Calculate the points from the form +Total=0 +for i in ${Points[*]}; do + Total=$((Total+i)) +done + +# Print the total points and grade +echo "Your total points on the test was: $Total" + +if [ $Total -lt $G ]; then + echo "Your grade is: IG" +elif [ $Total -ge $VG ]; then + echo "Your grade is: VG" +else + echo "Your grade is G" +fi + +exit 0