Special Characters


Special characters, which have a special meaning to the shell, are discussed in "Filename Generation/Pathname Expansion" on page 133. These characters are mentioned here so that you can avoid accidentally using them as regular characters until you understand how the shell interprets them. For example, avoid using any of these characters in a filename (even though emacs and some other programs do) until you learn how to quote them (next). The standard special characters are

& ; | * ? ' " ` [ ] ( ) $ < > { } ^ # / \ % ! ~ + 


Although not considered special characters, RETURN, SPACE, and TAB also have special meanings to the shell. RETURN usually ends a command line and initiates execution of a command. The SPACE and TAB characters separate elements on the command line and are collectively known as whitespace or blanks.

Quoting special characters

If you need to use as a regular character one of the characters that has a special meaning to the shell, you can quote (or escape) it. When you quote a special character, you keep the shell from giving it special meaning. The shell treats a quoted special character as a regular character. However, a slash (/) is always a separator in a pathname, even when you quote it.

To quote a character, precede it with a backslash (\). When you have two or more special characters together, you must precede each with a backslash (for example, enter ** as \*\*). You can quote a backslash just as you would quote any other special characterby preceding it with a backslash (\\).

Another way of quoting special characters is to enclose them between single quotation marks, as in '**'. You can quote many special and regular characters between a pair of single quotation marks, as in 'This is a special character: >'. The regular characters remain regular, and the shell also interprets the special characters as regular characters.

The only way to quote the erase character (CONTROL-H), the line kill character (CONTROL-U), and other control characters (try CONTROL-M) is by preceding any one with a CONTROL-V. Single quotation marks and backslashes do not work. Try the following:

$ echo 'xxxxxx CONTROL-U' $ echo 'xxxxxx CONTROL-V CONTROL-U' 





A Practical Guide to UNIX[r] for Mac OS[r] X Users
A Practical Guide to UNIX for Mac OS X Users
ISBN: 0131863339
EAN: 2147483647
Year: 2005
Pages: 234

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net