This question is a continuation of the Lab 3 and 4 questions. You will be able to continue working with the script you submitted before, or with the solution posted on the course website. You can find the necessary background, as well as the requirements of the Lab 3 and 4 questions on the previous page. The following assumes you are familiar with Labs 3 and 4.
For this test, you can assume that all database files your script will be tested with will have correct format.
For your convenience, you can download the sample database used in Labs 3 and 4 here.
lt1t.sh
in your favourite editor
so that it implements the functionality described in the Requirements
section below.
submit 2031 LT1T lt1t.sh
submit
command can be viewed by
typing man submit
. In addition to the commands introduced in Labs 3 and 4, your script must implement the following command:
delent ent output.txt threshold
The expected behaviour is the following:
If the database has not been set by a successful setdb
command, then your script must respond with
Database has not been set.
followed by a new prompt.
If there are less than two arguments, your script must respond with
Missing Arguments.
followed by a new prompt.
If the first argument does not correspond to an entity in the database file, your script must respond with
Entity ent does not exist.
followed by a new prompt.
If a file whose name matches the second argument exists already, your script must respond with something like
File output.txt exists. No output created.
followed by a new prompt.
If there are only two arguments, your script must create a new file whose name is the second argument and it contains all lines in the database except for the ones that refer to the entity specified by the first argument. You can assume that your script always has permissions to create the output file. Your script must also output to the standard output a message such as the following
Added 5 lines to file output.txt
If there is a third argument, you can assume that it will always be an integer number. If such an argument exists, your script should create the output file as described above only if the number of references to the entity specified by the first argument is larger than the threshold indicated by the third argument. If the file is not created, your script must output to the standard output a message such as the following
Not enough references to entity ent
Your script must ignore any further arguments to
delent
without warning the user.
Following is a sample run that shows the expected behaviour of the script.
% lt1m.sh Grock- hello Unrecognized command. Grock- setdb Missing Argument. Grock- setdbb example.txt Unrecognized command. Grock- delent class2 inheritance.txt Database has not been set. Grock- setdb example.txt Database set to example.txt Grock- delent Missing Arguments. Grock- delent class2 Missing Arguments. Grock- delent ent output.txt Entity ent does not exist. Grock- delent class3 output_sample_run.fout Added 1 lines to file output_sample_run.fout Grock- delent class3 output_sample_run.fout File output_sample_run.fout exists. No output created. Grock- delent class3 output.txt 3 Not enough references to entity class3 Grock- quit % cat output_sample_run.fout inherit class1 class2 %