Sample Midterm #1

1. (4 points) If the current working directory is /usr/bishop/tmp, give an absolute path name without any . or .. directories in it for:

  1. ../src/./../passwd+/misc/./root.c
  2. /usr/holly/files/../DMS/././.././DMS/schedule
2. (5 points) If I wanted to send the output of the command from to the file FROM.OUT, and the error messages to the terminal, what would I type to the C shell?

3. (4 points) What command would I type to print a list of files that have names ending in ".c" and that contain the string "<stdio.h>"?

4. (5 points) How can you delete a file named -i?

5. (8 points) How does the shell use the path variable (in C shell, path; in Bourne shell, PATH)?

6. (15 points) What does the following print? If the ANSI standard says that more than one output is possible, give them all and explain why more than one is possible.


7. (14 points) Evaluate the expressions below, and give the values of the named variables after the expression has been evaluated. If the expression contains a syntax error, or if a value is undefined, say so. Treat each part as separate; that is, assume the following variable values for all parts, regardless of whether a previous part has changed them.
  1. x = a++ ? b++ : c++; give values of x, a, b, c
  2. x = (a || b++) && (c++ || a++); give values of x, a, b, c
  3. x = b < c < b; give value of x
  4. x = a + b / c; give value of x
  5. x = (c % d) + ((c / d) * d); give value of x
  6. x = dx = 3.2; give value of x and dx;
  7. x = a < d, --c < b; give value of x
8. (15 points) What is the output of the following program:

9. (15 points) What is the value of n after the following code executes?

10. (15 points) In the following:
  1. What happens when this portion of the program is compiled?
  2. What happens when this portion of the program is executed and the user types in the string "This is ECS40" followed by a carriage return (newline)?