KIT213 Operating Systems Winter School, 2022
Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit
KIT213 Operating Systems
Winter School, 2022
Assignment – UNIX Shell Programming
Assignment Specification
Write a shell script (to run on the Bourne shell) that allows a user to view, add, or delete a setting in a configuration file (config.txt) that contains settings in the form variable=value. The following is an example of such configuration file:
HOME=/u/soc/abc HOST=lawson HOSTTYPE=sun4 LOGNAME=abc OSTYPE=solaris PATH=/usr/dt/bin:/usr/openwin/bin:/bin:. PS1=$ PS2=> SHELL=/usr/bin/tcsh TZ=Australia/Tasmania USER=abc VENDOR=sun EDITOR=joe |
Your script for this task must be named setting.sh. For ease of use, your script must present a menu of operations that a user may choose from. After the user makes a selection and that the selected operation has been completed, the menu must be displayed again so that the user can make another selection. Validation check on user inputs is required (see the following sample output about this). In the beginning of your script you need to check to see whether the required configuration file (config.txt) actually exists under the current directory (if not, your script displays a message and then exits).
Here is a sample output of your script. The $ is the shell prompt. The items in italics are not part of the sample output. They are hints indicating how your script should behave.
$ ./setting.sh *** MENU *** 1. Add a Setting 2. Delete a Setting 3. View a Setting 4. View All Settings Q – Quit CHOICE: 1 (user input) Enter setting (format: ABCD=abcd): (user simply presses the Enter/Return key) New setting not entered Enter setting (format: ABCD=abcd): EDITOR (user input) Invalid setting (A valid setting needs to contain a “=” sign) Enter setting (format: ABCD=abcd): EDITOR= (user input) |
The variable name of the setting is: EDITOR
The variable value of the setting is:
Invalid setting .
(Hint: To retrieve a variable name before the “=” sign, research the expr command’s ability in handling strings)
Enter setting (format: ABCD=abcd): =vi (user input)
The variable name of the setting is:
The variable value of the setting is: vi
Invalid setting .
Enter setting (format: ABCD=abcd): 1EDITOR=vi (user input)
The variable name of the setting is: 1EDITOR
The variable value of the setting is: vi Invalid setting. The first character of a variable name cannot be a digit.
Enter setting (format: ABCD=abcd): EDITOR=vi (user input)
The variable name of the setting is: EDITOR
The variable value of the setting is: vi
New setting added .
*** MENU ***
1. Add a Setting
2. Delete a Setting
3. View a Setting
4. View All Settings
Q - Quit
CHOICE: 1 (user input)
Enter setting (format: ABCD=abcd): USER=jchen (user input)
The variable name of the setting is: USER
The variable value of the setting is: jchen Variable exists. Changing the values of existing variables is not allowed. *** MENU *** 1. Add a Setting 2. Delete a Setting 3. View a Setting 4. View All Settings Q - Quit
CHOICE: 2 (user input)
Enter variable name: EDTOR (user input) Variable does not exist. (Your script needs to check whether a variable exists or not) *** MENU *** 1. Add a Setting 2. Delete a Setting 3. View a Setting 4. View All Settings Q - Quit
CHOICE: 2 (user input)
Enter variable name: EDITOR (user input)
EDITOR=vi
Delete this setting (y/n)? y (user input)
Setting deleted (However, if user’s answer is n here, then the setting stays)
*** MENU ***
1. Add a Setting
2. Delete a Setting
3. View a Setting
4. View All Settings Q - Quit
CHOICE: 3
Enter variable name:USER1 (user input)
Variable does not exist. (Your script needs to check whether a variable exists or not)
*** MENU ***
1. Add a Setting
2. Delete a Setting
3. View a Setting
4. View All Settings Q - Quit
CHOICE: 3 (user input)
Enter variable name: USER (user input)
USER=abc
Requested setting displayed above.
*** MENU ***
1. Add a Setting
2. Delete a Setting
3. View a Setting
4. View All Settings Q - Quit
CHOICE: 4 (user input)
HOME=/u/soc/abc
HOST=lawson
HOSTTYPE=sun4
LOGNAME=abc
OSTYPE=solaris
PATH=/usr/dt/bin:/usr/openwin/bin:/bin:.
PS1=$
PS2=>
SHELL=/usr/bin/tcsh
TZ=Australia/Tasmania
USER=abc
VENDOR=sun
*** MENU ***
1. Add a Setting
2. Delete a Setting
3. View a Setting
4. View All Settings Q - Quit
CHOICE: 5 (user input)
Invalid choice.
*** MENU ***
1. Add a Setting
2. Delete a Setting
3. View a Setting
For Your Assignment Script
You must
•
•
•
•
•
Include your name, student ID, and a brief introduction of what the script does as a comment in the beginning of the script.
Make your script run on the Bourne shell, regardless of which shell the user of your scripts is currently on.
Add in-line comments to help other people understand your script. Use “\n” where appropriate to make the output of your script more readable.
Note that your script structure and layout are also important as they will be marked as part of the assessment process.
Submitting Your Assignment
You must submit a single folder named kit213agn which contains the following two (2) files, electronically to the kit213submit folder which will be created for you in your ictteach home account:
setting.sh, config.txt
(Please make sure that your kit213agn folder only contains the two files as listed here, when you are ready to submit them.)
To submit your assignment, follow these three steps:
1). Ensure that both your kit213agn folder and your kit213submit folder are stored right under your home directory;
2). Run the following commands to copy your kit213agn folder into your kit213submit folder (the $ is the shell prompt):
$ cd (This takes you back to your home directory from anywhere) $ cp -r kit213agn kit213submit (This copies your assignment folder into your kit213submit folder. The option -r is important) $ ls -l kit213submit (This verifies that your assignment folder is now in your kit213submit folder) $ ls -l kit213submit/kit213agn (This verifies that your assignment files are now in your kit213submit folder) |
3). Immediately use your mobile phone (or a snipping tool installed on your laptop) to make a screenshot of your secure shell window (such as PuTTY window) and submit the image file to KIT213 MyLO (under Assessments, then Assignments), as proof of your assignment submission. Use your name and ID number as the image file name, for example, Smith_John_012345.jpg. If your assignment files are copied into the kit213submit folder by the deadline, you do not receive any penalty if this image file is slightly late.
IMPORTANT NOTE: The kit213submit directory/folder will be created for you automatically by the ictteach system administrator close to the submission time – do not create it yourself as this will cause your assignment to not be submitted correctly. If the kit213submit folder does not exist one week before the assignment deadline, please advise the Unit Coordinator immediately ([email protected]). Without a kit213submit folder, you will not be able to submit your assignment.
If your assignment is late then you should submit your files to the kit213late folder. The late folder will be created automatically after the due date and will be available for one week only.
Need Help?
You are encouraged to seek assistance from your lecturer after you have seriously thought about the assignment. Please note that we can provide general advice, however, we will not help you write any code, nor will we help you debug.
2022-07-07
Assignment – UNIX Shell Programming