GTU OS Program - 3
3. Write a shell script to generate marksheet of a student. Take 3 subjects, calculate and display total marks, percentage and Class obtained by the student.
Make a file called marksheet.sh using vim. If you want a full guide to vim than you can check this post.
tkanu025@hp:~/lab_solutions$ vim marksheet.sh
When you will hit enter than it will open a window like the one below. This is
an editor and Here you can write your code.
Press i to enter into the insert mode
Write full code there like this
- echo "Enter marks(out of 30) of "
- read -p "Subject 1: " s1
- read -p "Subject 2: " s2
- read -p "Subject 3: " s3
- sum=`expr $s1 + $s2 + $s3`
- echo "Sum of marks of 3 subjects is : "$sum
- per=`expr $sum \* 10 / 9`
- echo "Percentage: "$per
- if [ $per -ge 60 ]
- then
- echo "you got Distinction"
- elif [ $per -ge 50 ]
- then
- echo "you got First class"
- elif [ $per -ge 40 ]
- then
- echo "You got second class"
- else
- echo "sorry you failed! better luck next time"
- fi
Then press ESC and then Enter :wq which will bring you out of the vim editor writing that code into your marksheet.sh file.
Now compile and run the created file.
tkanu025@hp:~/lab_solutions$ chmod +x marksheet.sh tkanu025@hp:~/lab_solutions$ ./marksheet.sh
Here is the Output of this program
Comments