Chapter 7 - The C Shell

Quiz

1. Why do you think integer expressions must be preceded by an @ sign?
Many of the mathematical operators in the C shell have other meanings to the shell itself (e.g. * ) so @ is a way to tell the shell that youíre performing an integer operation on the values specified. This guarantees that the operator is used as intended.
2. Whatís a good way to correct a simple typing mistake on the previous command?
You can use ìhistory substitutionî to correct a simple typing mistake you made on the previous command.
3. Whatís the function of the {} metacharacters?
These metacharacters are used to abbreviate filenames or arguments with common parts so that you only have to type the repeated portions once.
4. Describe the differences between the set and setenv built-in commands.
The set built-in sets the value of a shell variable, the setenv built-in sets the value of an environment variable (i.e. a variable whose value will be passed to a subshell).
5. How do you protect files from accidental overwrites?
Typing the C shell command ìset noclobberî will prevent the shell from overwriting a file specified with the standard output redirection symbol ì>î.
6. How do you protect scripts from Control-C interrupts?
You can protect a C shell script from Control-C interrupts by using the onintr built-in command to trap the interrupt.

Exercises

7.1 Write a C shell version of the track script that was described in Chapter No, 5. [level: easy]
This exercise will point out many of the syntactic difference between Bourne and C shell scripting.
7.2 Write a utility called hunt that acts as a front end to find; hunt takes the name of a file as its single parameter and displays the full path name of every matching filename, searching downwards from the current directory. [level: medium]
Use find with the -name argument to find all files of the same name from the current directory on down.

Project

Study the current trends in object-oriented programming, and then design an object-oriented shell (a C++ shell?). [level: hard]
This could be a full semester project depending on the depth to which it is taken. Another interesting study might be the Plan 9 operating system developed at AT&T which treats many system resources as objects (e.g. print jobs, files).