OPS435 Week 8



Reality Check


Word Problem


Write a portable Bash Shell script called getStats.bash that uses a valid file pathname as the first argument.


If there is not exactly one argument after your command, you will display a USAGE error message and exit the shell script with a false value. If there is one argument, but it is NOT a valid regular file, then you will display an error message, and exit the shell script with a false value.


If there is exactly one argument after your command, and it contains a valid regular file pathname, your shell script is designed to count the number of students enrolled in your sections a, b and c of the course ops435.


Refer to sample run below for data file format and command runs....


Sample Runs (Commands or shell script appears in bold)


cat courses.dat

ops435a:Murray Saul

ops435a:Evan Weaver

ops435b:Mohammad khan

ops435c:Brian Perry

ops435b:Mark Fernandes

ops435b:Mike Martin

ops435a:Chris Tyler

ops435a:John Selmys

./getStats.bash

USAGE: ./getStats.bash [datafile]

./getStats.bash nofile.txt

Filename "nofile.txt" does not exist

./getStats.bash courses.dat

Enrollment statistics:

Section A: 4

Section B: 3

Section C: 9

ANSWER:




OPS435 Page 2 of 2 pages