CS313 Fall 2004
LAB 2

MORE UNIX SKILL

I would like you to try a few small things in this lab.

Let's make sure you can do some of the things required for
success in Project 1.

1.  Secure shell into k9.cs.wustl.edu.  Make a directory
with your team name(s) under the 04-01 directory using mkdir.
Copy offers and payoffs into your directory.

2.  Create a file in the directory called neg.  Make
it a gawk program that says "hello world" and has the shbang
at the top #!.  Use chmod a+rx to make this executable.
Try executing it using "./neg".

3.  Try writing "hello" to /dev/stdout and "goodbye" to /dev/stderr.
Prove that one output went to the first by piping the output to
a file when you execute the command.

4.  Change your program so that it reads from the offers file.
Each line you read, write TWICE to /dev/stdout.

5.  Change your program so that it reads the offers file TWICE.
Each line you read, write ONCE to /dev/stdout.  You have
to use close("offers") in between your while(getline < "offers")
loops.

6.  Change your program so that it reads a number from /dev/stdin.
Print the input to /dev/stdout.  You can test your program by
saing echo INPUT | ./neg.

7.  Change your program so that the input has to be 1 or 2.  If
the input is not 1 or 2, then complain and exit.

8.  Last thing.  Change your program so that it reads the offers
file twice, after sleeping for 15 seconds in between.  If the file
has changed, say so by printing the word "CHANGED" to /dev/stdout.
If not, say "UNCHANGED".  Try run it and change the file while
it is sleeping by running the program in the background,
echo 1 | ./neg &.

If you have any questions, remember Rahul is cool.  And he knows
UNIX.