Escape character

From Wikipedia, the free encyclopedia

In computing and telecommunication, an escape character is a single character which in a sequence of characters signifies that what is to follow takes an alternative interpretation. The term escape sequence refers to the escape character and the subsequent character or characters so modified.

Contents

[edit] Examples

[edit] Bourne shell

In sh, the * character is special, expanding via globbing. In isolation, it expands to the names of all files in the current directory. So to refer to a file literally called * you need to tell the shell to not interpret it in this way, which you do by preceding it with a backslash (\) -- this escapes the * character. Compare:

   rm *
   = delete all files in the current directory
   rm \*
   = delete the file named *

[edit] Programming languages

Many modern programming languages specify the doublequote character (") as a delimiter for a string literal. The backslash escape character provides one way to include doublequotes inside a string literal. For example, in Perl:

   print "Nancy said "Hello World!" to the crowd.";

produces a syntax error, whereas:

   print "Nancy said \"Hello World!\" to the crowd.";

produces the intended output.

Some programming languages also provide other ways to prevent this type of error, without requiring an escape character (see e.g. delimiter collision).

[edit] Categories

  • In alphabet coding schemes, a specially designated character, the occurrence of which in the data signifies that one or more of the characters to follow are from a different character code, i.e., have meanings other than normal.
  • In a text-control sequence of characters, a control character that indicates the beginning of the sequence and the end of any preceding text. This is for instance used to control text terminals and printers (see escape sequence).
  • In the ASCII character code, the character ESC with decimal code 27 and hexadecimal code 1B.

Early reference to this term is found in Bob Bemer's IBM technical publications.

Some of this article is based on material from Federal Standard 1037C.

The Escape key is usually found on standard PC keyboards. However it is commonly absent from keyboards for PDAs and other devices not designed primarily for ASCII communications, and not generally used as part of the common user interface for applications on the Windows operating system. The DEC VT220 series was one of the few popular keyboards that did not have a dedicated Esc key, instead using one of the keys above the main keypad, though it is debatable if this contributed to the failure of the DEC personal computer series that used this keyboard.

[edit] External links

[edit] See also

In other languages