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 ',"
152 csh, pipes, and find Date: Mon, 7 May 90 18:00:27 -0700 From: Andy Beals bandy@lll-crg.llnl.gov Subject: Re: today’s gripe: fg %3 To: UNIX-HATERS Not only can you say %emacs or even %e to restart a job [if it’s a unique completion], one can also say %?foo if the substring “foo” appeared in the command line. Of course, !ema and !?foo also work for history substitution. However, the pinheads at UCB didn’t make !?foo recognize subse- quent editing commands so the brain-damaged c-shell won’t recog- nize things like !?foo:s/foo/bar&/:p making typing a pain. Was it really so hard to scan forward for that one editing character? All of this gets a little confusing, even for Unix “experts.” Take the case of Milt Epstein, who wanted a way of writing a shell script to determine the exact command line being typed, without any preprocessing by the shell. He found out that this wasn’t easy because the shell does so much on the program’s “behalf.” To avoid shell processing required an amazingly arcane incantation that not even most experts can understand. This is typi- cal of Unix, making apparently simple things incredibly difficult to do, simply because they weren’t thought of when Unix was first built: Date: 19 Aug 91 15:26:00 GMT From: Dan_Jacobson@att.com Subject: ${1+“$@”} in /bin/sh family of shells shell scripts Newsgroups: comp.emacs,gnu.emacs.help,comp.unix.shell On Sun, 18 Aug 91 18:21:58 -0500, Milt Epstein epstein@suna0.cs.uiuc.edu said: Milt what does the “${1+“$@”}” mean? I’m sure it’s to Milt read in the rest of the command line arguments, but Milt I’m not sure exactly what it means. It’s the way to exactly reproduce the command line arguments in the /bin/sh family of shells shell script.
Previous Page Next Page