Quoting Oddities
The quoting rules have a few exceptions. You probably won't run into these often, but it's good to be aware of them:
!
or$
at the end of an argument is not interpreted as special and does not need quoting:%
echo x! x$
x! x$A backslash inside quote marks is normally left alone, as demonstrated below where the quotes protect the backslash in the second and third arguments:
%
echo \x '\x' "\x"
x \x \xHowever, if a backslash occurs before
!
, it is always interpreted as a quote character. Notice how the backslash disappears in the following example, even when it appears within quote marks:%
echo \!x '\!x' "\!x"
!x !x !xThis result occurs because
\
is the only way to turn off!
; therefore,\!
is interpreted as a literal!
regardless of its context.!
,`
, and$
normally retain their special meaning inside double quotes. You can turn off!
and`
(but not$
) by preceding each with a backslash:%
echo "\!x" "\`x\`"
!x `x`
% echo "\$shell"
/bin/tcsh
Inside double quotes, a $ is interpreted as beginning a variable reference, and you cannot turn it off, even with a backslash.
A single quote cannot appear within a single-quoted string, even if you use a backslash. The same is true of double quotes within a double-quoted string:
%
echo '\''
Unmatched '. %echo "\""
Unmatched ".
Get Using csh & tcsh now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.