- OPS435 -
OPEN SYSTEM AUTOMATION
Lab #5
FOCUS: Logic (Control Flow Statements)
PART A - Perform the following tasks:
- Logon to your Matrix account.
- Perform the week5 online tutorial called "Online Linux Tutorials". This tutorial must be completed to count as half of the mark for this lab #5. The tutorial, when properly completed will send your instructor and yourself an e-mail message to verify that the tutorial was completed.
Here is a link to the online tutorial instructions:
[ html ]
- Proceed to Part B
PART B - Perform the following tasks:
- Logon to your Matrix account. This lab requires that you use your
Matrix account in order to submit your lab.
- Make an empty directory, called lab05.
- Use the cd command to make lab05 your present working directory.
- Use a text editor to create a file called lab05.bash and add a shebang line to make it a portable Bash shell script.
- Add the following lines displayed below to your
existing shell script:
read -p "Enter a number (no decimals): " userNumber
echo
echo "Testing to see if number is even..."
echo -n "The exit status value \"\$?\" is: "
[ $((userNumber % 2)) -eq 0 ]
echo "$?"
- Save and exit your file called lab05.bash, set execute permissions for your newly-created file lab05.bash.
- Run this file twice: once, using an even number and once, using an odd number.
- Modify your shell script to add the additional commands displayed below:
echo
echo -n "Therefore, the number \"$userNumber\" is: "
if [ $((userNumber % 2)) -eq 0 ]
then
echo "EVEN"
else
echo "ODD"
fi
- Save and run your shell script. Test this out with an even number and an odd number,
and take time view the standard output, and what it means.
- Modify your shell script to include the following commands displayed below using the && and || constructs to acheive the same thing as the previous if-else statements:
echo -n "I repeat, the number \"$userNumber\" is: "
[ $((userNumber % 2)) -eq 0 ] && echo "EVEN" || echo "ODD"
echo
- Save and run your shell script and verify the results.
- Proceed to Part C
PART C - Write a shell script
- Make certain that you are currently located in the lab05 directory
- Create a portable bash shell script called checkArguments.bash
- Make certain that your shell script contains the appropriate shebang
line.
- Use logic in your shell script to test for the number of arguments NOT equal to 2.
Take the following action if test condition is TRUE:
- display the text "There are NOT exactly two arguments after your command"
- Take the following action is test condition is FALSE:
- display the text "There ARE exactly two arguments after your command"
- Add a line displaying the number of arguments that were entered after your command.
For example: "The number of arguments are: ..."
(Hint: look at course notes for "special parameters").
- Add another line to display the name of your shell script that your are running.
For example: "The name of this shell script is: ..."
- Save and run your shell script each time using:
- Zero arguments
- One argument
- Two arguments
- Three arguments
to ensure that your shell script works correctly.
- Proceed to Part D to submit your lab...
PART D - Submit your Lab #5:
- Make certain that you are currently located in the lab05 directory
- Issue
the following Bash Shell script to check and if correct, send e-mail to
your OPS435 professor (works only for Murray Saul's sections):
/home/murray.saul/labs/submit-lab5.bash
This shell script should either indicate problems and hints for you
to correct your shell script, or indicate that your lab #5 submission
was successful. If your lab was successfully submitted, both
you and your OPS435 professor (Murray Saul) should have received an e-mail message.
Note: Keep this e-mail message for the remainder of the semester as
date and time stamp proof that you submitted the lab in case
there is a discrepancy with your OPS435 lab grade...