DAT2330 - Mini-Lab #2 - Ian Allen - idallen@ncf.ca This Mini-Lab takes place on ACADAIX. The files are found in my directory: ~alleni/dat2330/ This Lab has three parts: Basic, Intermediate, and Advanced Part I - Basic Lab 1) When is the "-e" option to the "grep" command useful? In other words, when should you use this syntax? $ grep -e pattern file (HINT: RTFM) 2) What does the "-u" option to the ksh shell mean? (HINT: Run the output of "man ksh" into a pipe and into grep. You need to have answered Question 1 to do this correctly.) 3) Study the simple1.sh and simple2.sh shell scripts. Run them. 4) The shell script "makeandgo.sh" has some spelling and syntax errors and thus doesn't quite work. Copy the script and fix the errors. (The "-u" on the first line is not one of the errors.) 5) The C program that the script is building also has some syntax and spelling errors. Find the C programming errors and fix them. (Don't try to do this until you get the script itself working!) SPOILER HINT (use only when desperate): The compressed file answers.txt.gz contains the coded output of "diff" run on the working script and the damaged script. The encoding used to build this file was: diff makeandgo.sh ../makeandgogood.sh \ | tr 'n-za-mN-ZA-M' 'a-zA-Z' \ | gzip >answers.txt.gz When decoded, the file will tell you everything that needs fixing in the makeandgo.sh shell script. Use it only if you are desperate for an answer and your instructor isn't around to help. WARNING: DECODING AND READING THIS FILE GIVES YOU THE ANSWERS TO #3 and #4. You learn nothing by copying my answers. Part II - Intermediate Lab 6) Build a shell script named "makemake" that builds a Makefile for a program. The name of the program is the first argument. The base name of the object file, source file, and header file is the second argument. (We assume exactly two source files.) Your Unix account name (from the appropriate shell environment variable) should appear in a comment line in the Makefile that your script generates. Sample Usage: $ ./makemake foo bar $ cat Makefile # Makefile for foo generated by alleni foo: bar.o cc -o foo bar.o bar.o: bar.c bar.h cc -c bar.c Another Example: $ ./makemake zorg buzz $ cat Makefile # Makefile for zorg generated by alleni zorg: buzz.o cc -o zorg buzz.o buzz.o: buzz.c buzz.h cc -c buzz.c Your "makemake" script must create the Makefile itself, using the two command line arguments you give it. Required: 1. The name of the shell must be correctly given on the first line of your "makemake" shell script. 2. Your name and email address must appear as a comment in the script. (Always sign your programs.) Part II - Advanced Lab 7) Enhance your "makemake" script from Part II. If either of the source files is missing, print an error message and exit instead of going on to build the new Makefile. A command to test if a file exists is: test -e filename The above "test" command prints nothing; but, it returns status 0 if "filename" exists, and status non-zero if "filename" doesn't exist. The "test" command can test for all kinds of things: files, directories, symbolic links, permission to read, empty strings, etc. (RTFM) 8) Enhance your "makemake" script again. If either of the source names is a directory (not a plain file), print an appropriate error message and exit instead of going on to build the new Makefile. (RTFM) P.S. Test your program! Does it really detect a directory?