Assignment 2 - Longer Shell Scripts
Due by onQ Submission Before 7pm on Friday Oct. 9
Preamble
Make sure you have read the Assignment Submission page before you finish this assignment. In particular, note that you will have to upload a video that explains each of your scripts to indicate that you understand what you have written. And you need to have submitted your "Declaration" video before your assignment can be graded.
To write these scripts you will need to have understood the material in the first three topics in this course, including the use of loops and conditionals in a shell script. You should work through exercise 3 before starting on this assignment.
Description
Script 1: gradeDist.sh
Suppose you are working as a prof or TA and your students have an assignment which requires them each to hand in exactly one file. You've got a directory with all of the submitted files in it, and no other files. You're also lucky enough to have a script that will do all the work of marking a submission; it will take the name of a submission file as its only parameter and will print out a single upper-case letter (A, B, C, D or F) as its only output.
You'd like to know the distribution of marks in your class. Write a bash script called gradeDist.sh (the ".sh" extension is required!) that will take two parameters:
The name of your marking script
The name of the folder containing the assignment submission files
Your gradeDist.sh script must call the marking script to mark each file inside the folder and print a report showing the number of files earning each of the letter grades. If there are sub-folders inside the folder, your script must ignore them (and all of the files inside them). The only output of your gradeDist.sh script should be a list of how many submission files received each of the five possible marks.
Please look at the example transcript shown below for an example of the output format and follow that format as closely as possible.
Script 2: pigLatin.sh
Write a bash script called pigLatin.sh that will take one parameter. You may assume that the parameter is a string of lower-case letters. Your script must print the equivalent of that word in Pig Latin.
In case you are not familiar with Pig Latin, here are the rules that you must follow for this assignment:
If the word starts with a vowel (a,e,i,o or u), just add "way" to the end of the word. For example: "apple" in Pig Latin is “appleway” and "elephant"is “elephantway”.
If the word starts with one or more consonants (before the first vowel) move those consonants to the end of the word and add "ay". For example, "dog" becomes "ogday", "street" becomes "eetstray", "computer" becomes "omputercay" and "gradual" becomes "adualgray".
The letter "y" in English sometimes functions as a consonant and sometimes as a vowel. For the purposes of this assignment, you may assume that "y" at the start of a word is always a consonant. (I can't actually think of a counter-example, but if you think of one don't worry about it!) So "yellow" becomes "ellowyay" and "you" becomes "ouyay".
You may not assume any limit on the number of consonants that might appear at the beginning of the world, even though the limit in English is 3. So you should accept a word like "brzkleet", which you would translate to "eetbrzklay".
You may assume that every word contains at least one vowel.
Pig Latin is a rather silly children's game in which you transform words into a different form. For example, you might greet a fellow student by saying "ellohay, areway ouyay oinggay otay assclay odaytay?"
There are variations on Pig Latin. If you learned slightly different rules for Pig Latin, stick with the rules outlined above.
Error Handling
Your scripts must be able to handle the following four kinds of errors:
the gradeDist.sh script is called with a number of arguments other than two
the first argument to gradeDist.sh is not the name of an existing, executable file
the second argument to gradeDist.sh is not the name of an existing directory
the pigLatin.sh script is called with a number of arguments other than one
If any of these kinds of errors occur your scripts must print an informative error message to the standard error stream and exit immediately with a non-zero exit status. (You can choose any exit status number you want as long as it’s not zero.) "Informative" means that it must say enough to tell the user which one of the above list of errors has occured - for example "error: wrong number of arguments" or "error: first argument is not an executable file" instead of just "error" or something vague like “argument error”.
If no errors occur your scripts must exit with an exit status of zero.
Your scripts may ignore the possibility of any other kinds of errors -- for example, you don't have to worry about what happens if the marking script named by the first parameter prints something other than A, B, C, D or F.
Sample Transcript
This transcript is provided as an illustration. When marking your assignments we will use different test cases, so it's important that you try a variety of cases for each script to make sure that it works under all circumstances.
There is a directory containing 100 files that can be used to test the gradeDist.sh script. The names and sizes of the files were generated randomly. There are also two trivial marking scripts. The first (called grade1) marks files based on their size. The second (called grade2) marks files based on their names. A copy of the directory and the two marking scripts are posted in /cas/course/cisc220/assn2Examples, so if you want to, you can copy or refer to them and see if your own gradeDist.sh script gets the same results as shown below. You can also create your own marking scripts for testing if you wish. When we mark your submissions we will use a grading script that is different from both grade1.sh and grade2.sh.
ln -s /cas/course/cisc220/assn2Examples sampleDir
-------$ gradeDist.sh sampleDir/grade1.sh sampleDir/FILES
A: 9
B: 17
C: 45
D: 18
F: 11
-------$ echo $?
0
-------$ gradeDist.sh sampleDir/grade2.sh sampleDir/FILES
A: 7
B: 20
C: 41
D: 17
F: 15
-------$ echo $?
0
-------$ gradeDist.sh singleArg 2>|errMsg.txt
-------$ echo $?
1 (or any value other than 0)
-------$ cat errorMessage.txt
error: gradeDist.sh needs two arguments
-------$ gradeDist.sh noSuchScript sampleDir/FILES
error: noSuchScript is not an existing, executable file
-------$ echo $?
2 (or any value other than 0)
-------$ gradeDist.sh sampleDir/grade1.sh NO-SUCH-DIR
error: NO-SUCH-DIR does not exist or is not a directory
--------$ echo $?
3 (or any value other than 0)
-------$ pigLatin.sh dog
ogday
-------$ pigLatin.sh cat
atcay
(continued on next page)
-------$ pigLatin.sh trouble
oubletray
-------$ pigLatin.sh structure
ucturestray
-------$ pigLatin.sh egg
eggway
-------$ pigLatin.sh brchlect
ectbrchlay
-------$ pigLatin.sh o
oway
-------$ pigLatin.sh >|errMsg.txt
error: wrong number of arguments for pigLatin.sh (needs exactly one)
Grading
Hand in two separate files to onQ - making sure each has the *.sh extension. Try to put your explanations into a single video that you will also upload to onQ. You can re-submit if you make changes - we will only grade the newest submission.
Each script is worth 10 marks for a total out of 20. Even if your script works fine, your mark will be reduced if your video explanation shows that you do not fully understand what you have written. Note that "works fine" means that it must run properly on our CASLab VM - this is the standard. If your script will not run on CASLab, you will get a zero on that script. Make sure to write and edit your script using a Linux text editor only - this will help.
Click here to return to the home page
Last modified: 08/06/2020 00:42:56