Special Characters

 < Day Day Up > 

Special characters, which have a special meaning to the shell, are discussed in "Filename Generation/Pathname Expansion" on page 127. 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, it is best to avoid using any of the following characters in a filename (even though emacs and some other programs do) because they make the file harder to reference on the command line:

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

Whitespace

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.

If you need to use one of the characters that has a special meaning to the shell as a regular character, 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.

Backslash

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 character by preceding it with a backslash ( \\).

Single quotation marks

Another way of quoting special characters is to enclose them between single quotation marks: '**'. You can quote many special and regular characters between a pair of single quotation marks: '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 it with a CONTROL-V. Single quotation marks and backslashes do not work. Try the following:

 $ echo 'xxxxxxCONTROL-U' $ echo xxxxxxCONTROL-V CONTROL-U 

optional

Although you cannot see the CONTROL-U displayed by the second of the preceding pair of commands, it is there. The following command sends the output of echo (page 647) through a pipe (page 52) to od (page 737) to display the CONTROL-U as an octal 25 (025):

 $ echo xxxxxxCONTROL-V CONTROL-U | od -c 0000000   x   x   x   x   x   x 025  \n 0000010 

The \n is the NEWLINE character that echo sends at the end of its output.


     < Day Day Up > 


    A Practical Guide to LinuxR Commands, Editors, and Shell Programming
    A Practical Guide to LinuxR Commands, Editors, and Shell Programming
    ISBN: 131478230
    EAN: N/A
    Year: 2005
    Pages: 213

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