- OPS435 -


Lab #5

FOCUS: Logic (Control Flow Statements)

PART A - Perform the following tasks:

  1. Logon to your Matrix account.
  2. 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 ]

  3. Proceed to Part B

PART B - Perform the following tasks:

  1. Logon to your Matrix account. This lab requires that you use your Matrix account in order to submit your lab.
  2. Make an empty directory, called lab05.
  3. Use the cd command to make lab05 your present working directory.
  4. Use a text editor to create a file called lab05.bash and add a shebang line to make it a portable Bash shell script.
  5. Add the following lines displayed below to your existing shell script:

    read -p "Enter a number (no decimals): " userNumber
    echo "Testing to see if number is even..."
    echo -n "The exit status value \"\$?\" is: "
    [ $((userNumber % 2)) -eq 0 ]
    echo "$?"

  6. Save and exit your file called lab05.bash, set execute permissions for your newly-created file lab05.bash.
  7. Run this file twice: once, using an even number and once, using an odd number.
  8. Modify your shell script to add the additional commands displayed below:

    echo -n "Therefore, the number \"$userNumber\" is: "

    if [ $((userNumber % 2)) -eq 0 ]
    echo "EVEN"
    echo "ODD"

  9. 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.
  10. 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"

  11. Save and run your shell script and verify the results.
  12. Proceed to Part C

PART C - Write a shell script
  1. Make certain that you are currently located in the lab05 directory
  2. Create a portable bash shell script called checkArguments.bash
  3. Make certain that your shell script contains the appropriate shebang line.
  4. 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:
  5. Take the following action is test condition is FALSE:
  6. 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").
  7. Add another line to display the name of your shell script that your are running.
    For example: "The name of this shell script is: ..."
  8. Save and run your shell script each time using:
    to ensure that your shell script works correctly.
  9. Proceed to Part D to submit your lab...

PART D - Submit your Lab #5:
  1. Make certain that you are currently located in the lab05 directory
  2. 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):


    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...