150 csh, pipes, and find to any C-shell will cause it to crash immediately? Do you know why? Questions to think about: What does the shell do when you type “!xxx”? What must it be doing with your input when you type “!xxx%s%s%s%s%s%s%s%s” ? Why does this crash the shell? How could you (rather easily) rewrite the offending part of the shell so as not to have this problem? MOST IMPORTANTLY: Does it seem reasonable that you (yes, you!) can bring what may be the Future Operating System of the World to its knees in 21 key- strokes? Try it. By Unix’s design, crashing your shell kills all your processes and logs you out. Other operating systems will catch an invalid memory refer- ence and pop you into a debugger. Not Unix. Perhaps this is why Unix shells don’t let you extend them by loading new object code into their memory images, or by making calls to object code in other programs. It would be just too dangerous. Make one false move and—bam—you’re logged out. Zero tolerance for programmer error. The Metasyntactic Zoo The C Shell’s metasyntactic operator zoo results in numerous quoting problems and general confusion. Metasyntactic operators transform a com- mand before it is issued. We call the operators metasyntactic because they are not part of the syntax of a command, but operators on the command itself. Metasyntactic operators (sometimes called escape operators) are familiar to most programmers. For example, the backslash character (\) within strings in C is metasyntactic it doesn’t represent itself, but some operation on the following characters. When you want a metasyntactic operator to stand for itself, you have to use a quoting mechanism that tells the system to interpret the operator as simple text. For example, returning to our C string example, to get the backslash character in a string, it is nec- essary to write \\.
The Shell Game 151 Simple quoting barely works in the C Shell because no contract exists between the shell and the programs it invokes on the users’ behalf. For example, consider the simple command: grep string filename: The string argument contains characters that are defined by grep, such as ?, [, and ], that are metasyntactic to the shell. Which means that you might have to quote them. Then again, you might not, depending on the shell you use and how your environment variables are set. Searching for strings that contain periods or any pattern that begins with a dash complicates matters. Be sure to quote your meta character properly. Unfortunately, as with pattern matching, numerous incompatible quoting conventions are in use throughout the operating system. The C Shell’s metasyntatic zoo houses seven different families of metasyn- tatic operators. Because the zoo was populated over a period of time, and the cages are made of tin instead of steel, the inhabitants tend to stomp over each other. The seven different transformations on a shell command line are: As a result of this “design,” the question mark character is forever doomed to perform single-character matching: it can never be used for help on the command line because it is never passed to the user’s program, since Unix requires that this metasyntactic operator be interpreted by the shell. Having seven different classes of metasyntactic characters wouldn’t be so bad if they followed a logical order of operations and if their substitution rules were uniformly applied. But they don’t, and they’re not. Aliasing alias and unalias Command Output Substitution ` Filename Substitution *, ?, [] History Substitution !, ^ Variable Substitution $, set, and unset Process Substitutuion % Quoting ',"
Previous Page Next Page