Lab 4: Fun with shell variables and C programming!

Due Thursday, September 19

A program has been placed in /opt/cs228 named check_vars. It will verify your solutions to questions 1, 3, 4, and 5. This program is written in Python, and if you are curious what it looks like, you can examine it with cat, less, a text editor, etc.

As usual, place the commands you used to solve each of the 5 problems into a file called lab4. This time, suggestions for commands aren't given, for all questions, but a combination of export, grep, and tail should suffice.
  1. Add location of check_vars to PATH. The location is /opt/cs228. After this, you should be able to run check_vars.py without specifiying the path.
  2. Besides being used to set variables, the export command can print out a list of all variables defined for your shell session. Write a command which will print out all the variables which contain your username
  3. Set a variable named ANIMAL to the word giraffe. Remember to spell the word right! Then run check_vars.py, and if your variable is set correctly, the program will let you know.
  4. Place the secret code gerbil in a file, and set the variable CODEFILE to the path to this file. Run check_vars.py, and it will indicate if this is correct.
  5. Set the variable INDCMD to a command that prints the last line of /var/www/index.html. I recommend using tail for this purpose. Set the variable, and then run check_vars.py to see if it is correct.
  6. C Programming Problem: Create a program that will use the getenv function to get the environment variable named "TODO", and execute the contents of TODO on the shell using the system function. Name the program lab4.c or lab4.cpp, and put it wherever you put your answers to the other questions. It is possible to answer this question correct with only one line of code inside your main function, so if your answer is lengthy, do think about whether or not it may be overly complex.
Turn in your lab by creating a file named "lab4" with no extension in your home directory, with permissions set so that only you can view the file. This assignment is worth 35 points, 5 total from correct naming and permissions, and 5 from each of the problems above including the C programming problem.