ANSWERS TO UNIX SHELL EXERCISES



 1.    It prints the contents of the file rand.c to standard output.
       If the output is more than a screenful long, it pauses between
       each screenful.
          
 2.    The program generates 100 pseduo-random numbers between 0 and 999,
       and prints them to standard output. The numbers whiz by so fast that
       you can't read them.

          838
          758
          113
          ...
          139
          88
          521

 3.    The "mv" command renames the file a.out to rand. Now you can type
       "rand" just like any other Unix command and the rand.c program will
       be executed. This results in the same output as above.

 4.    The ">" redirects the output from standard output to the file named
       "data.txt". The data is displayed one screenful at a time using "more".

 5.    The "<" redirects the input from standard input to the file named
       "data.txt".  The "sort" command is built-in to Unix.  It sorts the
       data alphabetically and prints it to standard output. The "-n" flag is
       used to sort numeric data, e.g., so that 89 precedes 882 and.
          
 6.    This command redirects both standard input and standard output. Input is
       read in from the file data.txt and written to the file data-sorted.txt.

 7.    The '|' is used to chain the output of the first command to the input
       of the second. The output of our "rand" command is used as the input to
       the "more" command.

       The second command pipes the output of our "rand" command to the input
       of the "sort" command, and then the output of the sort command is used
       as the input to the more command.