This article explains quoting in C-type shells by comparing them to Bourne-type shell quoting. If you haven't read Section 27.12 about Bourne shell quoting, please do so now.
As in the Bourne shell, the overall idea of C shell quoting is this: quoting turns off (disables) the special meaning of characters. There are three quoting characters: a single quote ('), a double quote ("), and a backslash (\).
The C shell has a few more special characters in addition to the original Bourne shell:
! { } ~
Table 27-2 summarizes the rules; you might want to look back at it while you read the examples.
| 
 Quoting character  | 
 Explanation  | 
|---|---|
| 
 'xxx'  | 
 Disable all special characters in xxx except !.  | 
| 
 "xxx"  | 
 Disable all special characters in xxx except $, ', and !.  | 
| 
 \x  | 
 Disable special meaning of character x. At end of line, a \ treats the newline character like a space (continues line).  | 
The major differences between C and Bourne shell quoting are the following:
The exclamation point (!) character can be quoted only with a backslash. That's true inside and outside single or double quotes. So you can use history substitution (Section 30.8) inside quotes. For example:
% grep intelligent engineering file*.txt
grep: engineering: No such file or directory
% grep '!:1-2' !:3
grep 'intelligent engineering' file*.txt
    ...
In the Bourne shell, inside double quotes, a backslash (\) stops variable and command substitution (it turns off the special meaning of $ and ').
In the C shell, you can't disable the special meaning of $ or ' inside double quotes. You'll need a mixture of single and double quotes. For example, searching for the string use the `-c' switch takes some work:
% fgrep "use the \`-c' switch" *.txt Unmatched \`. % fgrep 'use the \`-c\' switch' *.txt Unmatched '. % fgrep "use the "'`-c'"' switch" *.txt hints.txt:Be sure to use the `-c' switch.
Section 29.10 shows an amazing pair of aliases that automate complicated C shell quoting problems like this.
In the Bourne shell, single and double quotes include newline characters. Once you open a single or double quote, you can type multiple lines before the closing quote.
In the C shell, if the quotes on a command line don't match, the shell will print an error unless the line ends with a backslash. In other words, to quote more than one line, type a backslash at the end of each line before the last line. Inside single or double quotes, the backslash-newline becomes a newline. Unquoted, backslash-newline is an argument separator:
% echo "one\ ? two" three\ ? four one two three four
Copyright © 2003 O'Reilly & Associates. All rights reserved.