Question: This lab is asking you to use getopts commend/program to process command-line options passed to your script. Make sure to understand slides 66-69 (last three
This lab is asking you to use getopts commend/program to process command-line options passed to your script. Make sure to understand slides 66-69 (last three pages of the PDF document) of 03 -- Bash Shell Programming materials (which you can find in Blackboards Course Content) and/or related textbooks chapters before starting.
What you should do:
Write a bash script that checks if options a, b, c, and d where used by the user when your script was invoked (called), where option a and d must take arguments
Your script should generate (handle) error messages
Your script should display to the screen (terminal) information which, if any, option was triggered or feedback to the user (me) that the user (I) tried to invoke invalid (unexpected) option or an error message if the right option was used by the user (me) but it expects argument that was not provided
Name your script Lab_8_YourName.sh and submit it uncompressed via Blackboard. If you scripts works only partially, let me know it by providing appropriate information in the notes for your submission. The deadline for this lab is before our next class meeting.
Hint, your script should include a very similar (but extended) code from the last slide of 03 -- Bash Shell Programming.
Some examples on how your script should behave:
If I run your script by typing: ./Lab_8_YourName.sh -b it should display: Option -b- was triggered.
If I run your script by typing: ./Lab_8_YourName.sh -a a_argument it should display: Option -a- was triggered with argument: a_argument.
If I run your script by typing: ./Lab_8_YourName.sh -d it should display: Option -d- expects its argument that was not provided.
If I run your script by typing: ./Lab_8_YourName.sh -e it should display: Invalid option -e-. The valid options are -a-, -b-, -c-, and -d-, where options -a- and -d- must be followed by an argument.
If I run your script by typing: ./Lab_8_YourName.sh it should display: No options were triggered.
Etc.
Extra credit (up to 90 points)
Let your script handle additional arguments after the (eventual) options. For example:
If I run your script by typing: ./Lab_9_YourName.sh -b arg_1 arg_2 it should display: Option -b- was triggered and arguments arg_1 arg_2 was(were) passed to the script.
Note that it is not a trivial problem, as I can call your script with multiple options and argument(s) to the script, option with argument for that option and argument(s) to the script (e.g., arg_1 arg_2), or no option with many arguments to the script, etc.. More cases your script handles, more extra points you will receive but you can print all arguments to your script at one (e.g., by using $@ or $*).
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
