Quoting
[me@linuxbox ~]$ echo text ~/*.txt {a,b} $(echo foo) $((2+2)) $USER
text /home/me/ls-output.txt a b foo 4 me
[me@linuxbox ~]$ echo "text ~/*.txt {a,b} $(echo foo) $((2+2)) $USER"
text ~/*.txt {a,b} foo 4 me
[me@linuxbox ~]$ echo 'text ~/*.txt {a,b} $(echo foo) $((2+2)) $USER'
text ~/*.txt {a,b} $(echo foo) $((2+2)) $USER
As we can see, with each succeeding level of quoting, more and more of the expansions
are suppressed.
Escaping Characters
Sometimes we only want to quote a single character. To do this, we can precede a charac-
ter with a backslash, which in this context is called the escape character. Often this is
done inside double quotes to selectively prevent an expansion:
[me@linuxbox ~]$ echo "The balance for user $USER is: \$5.00"
The balance for user me is: $5.00
It is also common to use escaping to eliminate the special meaning of a character in a
filename. For example, it is possible to use characters in filenames that normally have
special meaning to the shell. These would include “$”, “!”, “&”, “, and others. To in-
clude a special character in a filename you can to this:
[me@linuxbox ~]$ mv bad\&filename good_filename
To allow a backslash character to appear, escape it by typing “\\”. Note that within single
quotes, the backslash loses its special meaning and is treated as an ordinary character.
Backslash Escape Sequences
In addition to its role as the escape character, the backslash is also used as part of
a notation to represent certain special characters called control codes. The first 32
characters in the ASCII coding scheme are used to transmit commands to tele-
type-like devices. Some of these codes are familiar (tab, backspace, linefeed, and
carriage return), while others are not (null, end-of-transmission, and acknowl-
edge).
77