Assignment 1

Due Date and Deliverables

This assignment is due by midnight, February 16.

You are to submit three files, consisting of one KornShell script and two C source files. Send them as attachments to an email message. The contents are described below.

The Shell Script

Write a shell script named printargs that prints four lines. The first line tells the name that was used to invoke the script, the second line tells how many parameters there were, the third line tells what the last parameter was, and the fourth line tells what the first parameter was.

For example:

    $ printargs a b c
    My name is printargs.
    There were 3 parameters.
    The last one was c.
    The first one was a.
    $ 
You may use the shift command, but you are not to use any loops. Read about the shift command in Chapter 5, and look it up in Appendix B.

The C Program

The first source file is to be named printargs.c, and is to #include a header file named do_print.h. It is to contain a definition of the method main(), which is to receive the standard three arguments. main() is to pass the first two arguments to a function named do_print(), and then it is to print each of the environment variables, one per line.

The second source file is to be named do_print.c. It must also #include do_print.h, and is to contain the definition of do_print(), which is to print each of the command line arguments in reverse order before it returns.

For example:

    $ gcc -g -Wall printargs.c do_print.c -o printargs
    $ ./printargs you? are How there. Hello,
    The command line arguments are: Hello, there. How are you? ./printargs
       _=./printargs
       TZ=
       PATH=/usr/users/vickery/bin:/sbin:/usr/sbin:/usr/bin:/usr/ccs/bin:/usr/bin/X11
     :/usr/local/:/usr/local/bin:.
       WINDOWID=4194317
       EDITOR=vim
       LOGNAME=vickery
       ENV=.kshrc
       SHELL=/usr/local/bin/ksh
       DISPLAY=149.4.38.2:0.0
       LESS=-EaP?n?f%f .?m(File %i of %m) \
     ..?lt%lb/%L:?pt%pB\%:?bt%bB/%B:-...?e (end)? x Next\: %x..
       PRINTER=i2
       PAGER=less
       LOGHOST=qcunix1.acc.qc.edu
       FPATH=:/usr/users/vickery/fun
      <A long list follows>

Document Your Code

There are few formal rules for documenting your KornShell programs this semester. Just be sure to put the name of the file and your name in the first few lines, and use comments elsewhere to indicate logical sections of the code.

For C programs, you are to follow the [ Coding Guidelines ] web page for this course.