CST8204: Lab Exercise 1

Hello, World!

You have just been hired (w00t!) at a software development company that uses Linux for all its development work. You feel you are a little rusty, so on your first day (between visits to HR) you take a few minutes to refresh your memory.

First, using the vi editor, you create a little bash script that displays Hello, World!. You then modify it to display all its command-line arguments. Pleased with your success, you go on to create a little C program to duplicate your second script (that is, to display all elements of argv).

You recall that the man command will remind you how a function is to be used and what #include files it needs, and that you can specify a section number to make sure you get the right version. That is, if the reference is to strcpy(3), you issue the command man 3 strcpy. You also look up strcat(3) and printf(3), but you remember about character arrays, argc, and argv on your own. You can also look these items up in your copy of K&R2, The C Programming Language text and in the Lab Prep document.

The guy in the next cube tells you this command will take the C source file hello.c, compile it, link it with the library functions, and produce an executable program named hello.

gcc -ansi -pedantic -Wall -Wextra -O2 -o hello hello.c

Sure enough, it works. You test your program with several sets of command line arguments to be sure, including no arguments at all. You fix your program to test for no arguments being present, and re-run the tests.

Objectives for today's lab:

Before the end of today's lab period, demonstrate your two scripts, to be named hello1 (display "Hello, World!") and hello2 (display all arguments), and your C program hello.c and its compiled form hello (display all arguments) to your lab instructor for grading.



Be sure that you have completed a sign-in sheet for recording your weekly attendance and lab marks, and signed in for Week 1.

You may also wish to change your configuration in .bashrc or .bash_profile to (for example) change your search path, establish your umask (I use 077 in the lab), and so on. Make a back-up copy of any file before changing anything, and keep an xterm window open in case you have to repair a file after testing.



You should create a directory structure to use for this course (you will need this for most assignments and lab exercises). Experienced users often create ~/bin and ~/tmp directories as well, and keep $HOME largely empty.

One good approach is to create a high-level directory for each category, with a subdirectory for each assignment and exercise

For example:

~/cst8204




asgs




asg1



asg2



asg3



asg4


labs




lab1



lab2



lab3



...



lab14

I myself find "asg" much easier to type than "assingment" or whatever.