Lab2 FAQ

This document contains Frequently Asked Questions, which are relevant to completing the week's labassignment. Any Questions may be posted to cspp51081.

Here Documents and Shell Scripts: Help for Exercise 1.

To recieve full credit for this exercise, you must provide a shell script whichwill change all of you files ending in ".c" in your current directory: even if there are a thousandfiles. Sounds daunting, but I walk you through Here documents and Shell scripts.

Bonus points for Exercise 1

Write a script which excepts which files are to be changed from the command line. The user must be able to type:

       % myscript  files

and make the changes to all the files. For example, to change the C files in the current directory the user would type "*.c" or for the header files, the user would "*.h". Your script should also check that the user entered an argument to your command, and print a message of the correct usage if the user fails to do this. This sounds daunting, but it only requires a few changes to your script. Here is a hint: The Bash shell has two special variables:

Bonus points for Exercise 2

Write your gawk script so that the user can type any two-letter state abbreviation and any three-letter month abbreviation, and have the contents displayed. This should only take a couple of changes to your script.

Submitting Bonus Credit

The only way to recieve credit for bonus, is to follow the submission procedure below.

How the homework will be tested.

Exercise 1: We will have several C files (ending in '.c'), and will expect that when we run your shell script on the command line

  % ex1

the files will be correctly changed: with "stdio.h" replaced by "STDIO.h".

Exercise 2: You will need an awk script file (this simply means a file written for awk to read, and requires nothing special on your part), which we will test by running:

  % awk -f ex2.awk normal.precip.txt

       The normal rainfall for Alaska is XX.XX
       The normal rainfall for California is XX.XX
       The normal rainfall for Texas is XX.XX

Your script does not need to reproduce this text exactly, but must identify the state and the correct rainfall.

Submitting the Bonus, a clarification.

If you plan on writing versions of the exercise which are more robust (as explained above), you only need to submit two script files ex1 and ex2 plus a document entitled README to explain the correct commandline syntax and what your script does.
Exercise 1: Your script will need to take a command line argument specifying the files to be changed (this will be input by the user.) For example,

  % ex1 *.c

Exercise 2: You will probably want to implement ex2 as a shell script, since it will need arguments supplied by the user. For example

  % ex2.awk CA JAN

       The normal rainfall for CA in the month of JAN is XX.XX

The exact output is up to you but it must identify the state and month.