- OPS435 -
OPEN SYSTEM AUTOMATION
Lab #6
FOCUS: Logic & Loops
PART A - Perform the following tasks:
- Logon to your Matrix account.
- Perform the week6 online tutorial called "Online Linux Tutorials". This tutorial must be completed to count as half of the mark for this lab #6. 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 lab06.
- Use the cd command to make lab06 your present working directory.
- Use a text editor to create a file called lab06.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:
case $# in
1) text=$1
repetitions=5
;;
2) text=$1
repetitions=$2
;;
*) echo "USAGE: $0 [text][# of repetitions]" >&2
exit 1
esac
- Save and exit your file called lab06.bash, set execute permissions for your newly-created file lab06.bash.
- Run this without any arguments. What happens? What happens when you run the
following command displayed below:
./lab06.bash 2> error
- Issue the following command:
echo $?
Try to think of why the value of $? is displayed that way...
- Add the following lines displayed below into your shell script:
for (( x=1;x<=repetitions;x++ ))
do
echo "text is $text"
done
- Save changes, and run your shell scripts twice as displayed below:
./lab06.bash one
./lab06.bash one 3
Try to understand in terms of the "for" loop what happened for each situation.
- Add the following lines to your shell script:
set this and that
for x
do
echo $x
done
- Run your shell script as displayed below:
./lab06.bash one 4
Try to understand why the above result occurred...
- Add the following lines to your shell script:
answer=y
until [ "$answer" != "y" ]
do
read -p "Do you want to loop again? " answer
done
- Save your changes and run your shell script as shown in step #12.
Take time to see how the "until" loop works...
- Proceed to Part C
PART C - Write a shell script
- Make certain that you are currently located in the lab06 directory
- Create a portable bash shell script called testFilePathname.bash
- Make certain that your shell script contains the appropriate shebang
line.
- Add logic to force the user to enter AT LEAST one argument after your shell
script. If there are zero arguments, you need to display a USAGE statement
(as standard error), and terminate your shell script with a FALSE value.
- Use a loop that will run for EACH ARGUMENT after your shell script name
(i.e. a positional parameter) and display the argument followed by a message
if that file is or is NOT a regular file. Refer to sample run below:
PROVING FILES EXIST (OR NOT)
ls a b c
ls: cannot access a: No such file or directory
ls: cannot access c: No such file or directory
b
RUN #1
./testFilePathname.bash
USAGE: [file pathname(s)]
RUN #2
./testFilePathname.bash a b c
a is not a regular file
b is a regular file
c is not a regular file
- Save your changes, and run your shell script to make certain it works...
- Proceed to Part D to submit your lab...
PART D - Submit your Lab #6:
- Make certain that you are currently located in the lab06 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-lab6.bash
This shell script should either indicate problems and hints for you
to correct your shell script, or indicate that your lab #6 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...