Incomputing, anescape sequence is a sequence ofcharacters that has a specialsemantic meaning based on an established convention that specifies anescape character prefix in addition to thesyntax of the rest of thetext of a sequence.[1][2] A convention can define any particular character code as a sequence prefix. Some conventions use a normal, printable character such as backslash (\) or ampersand (&). Others use a non-printable (a.k.a. control) character such asASCIIescape.
Escape sequences date back at least to the 1874Baudot code.[3][4][5]
A common use of an escape sequence is to remove control characters from a data stream so that it does not cause its control function by mistake. The control character is replaced with an escape character and one or more other subsequent characters. After escaping the normal context in which the control character would have caused an action, the sequence is replaced by the removed character.[6] To transmit the escape character itself, two copies are sent.[7]
An escape sequence is often used incharacter andstring literals, to encode characters which are not printable or clash with the syntax of characters or strings. For example,control characters might not be allowed in a source file or may have undesirable side-effects if typed into a command.
InC and many derivative programming languages, a backslash (\) in astring literal marks the beginning of anescape sequence.[8][9] Common escape sequences include:carriage return\r,newline\n,tab\t. To account for the fact that using a printable character for escape causes that character to lose its normal meaning, a sequence of two backslash characters (\\) encodes a single backslash. An escape sequence can also specify a character by its code value. For example, the backslash can be encoded as either\x5c or\134 which specify the character code value ashexadecimal andoctal, respectively.
A backslash immediately followed by anewline (which is necessarily outside of a string literal) does not mark an escape sequence. TheC preprocessor joins the line with the subsequent line.[10]
When an escape character is needed within a string literal, there are two common strategies:
'He didn''t do it.')[7]echo Cut^&Paste outputs "Cut&Paste" in by escaping the ampersand operator with a caret (^)[6]In C and many related languages, the escape character is the backslash (\). The single quotation mark character can be coded as'\'' since''' is not valid. As a string literal isdelimited by double-quotes (") the content cannot contain a double-quote unless it is escaped ("\"") or via a sequence that specifies the code of the double-quote character (\x22).
InPerl orPython 2, the following is invalid syntax:
print"Nancy said "HelloWorld!" to the crowd."
This can be fixed by inserted backslash to escape:
print"Nancy said \"Hello World!\" to the crowd."
Alternatively, the following uses "\x" to indicate the subsequent two characters are hexadecimal digits; "22" being the hexadecimal ASCII value for double-quote.
print"Nancy said \x22Hello World!\x22 to the crowd."
C,C++,Java, andRuby allow the same two backslash escape styles.PostScript andrich text format (RTF) also use backslash escapes. Thequoted-printable encoding uses theequals sign as an escape character.URL andURI usepercent-encoding to quote characters with a special meaning, as for non-ASCII characters.
TheVT52 terminal used simpledigraph commands like escape-A. Without the escape character prefix,A simply meant the letterA, but as part of the escape sequenceescape-A, it had a different meaning. The VT52 also supported parameters. It was not a straightforward control language encoded as substitution.
The laterVT100 terminal implemented the more sophisticatedANSI escape sequences standard (now ECMA-48) for functions such as controlling cursor movement, character set, and display enhancements. TheHP 2640 series had perhaps the most elaborate escape sequences for block and character modes, programming keys and their soft labels, graphics vectors, and even saving data to tape or disk files.
InWindows (andMS-DOS), a utility,ANSI.SYS,[11] can be used to enable ANSI escape sequence support. In DOS via$e in thePROMPT command), and in 16-bit Windows via a command window. InUnix andUnix-like systems, the ANSI escape sequences are generally supported by theshell. The rise ofGUI applications has reduced the use of escape sequences, yet the ability to provide full-screen, text-based applications is still available.
A control sequence is a sequence of characters that changes thestate of a computerperipheral instead of conveying the normal information that the characters represent. In an ANSI escape sequence, the escape sequence prefix, calledcontrol sequence introducer, can be either ASCII ESC (decimal 27) followed by[ or CSI (decimal 155). Notable systems that did not use an escape character for control sequences include:
+++ that ismodal; switching from command to online mode. To ensure that the sequence is interpreted as a control sequence instead of embedded in content, the sender stops communication for one second before and after sending+++. When the modem detects condition, it switches from normal mode (sending characters to the phone) to a command mode in which the data is interpreted a command. Sending the O command switches back to the normal mode.[12][13][14][15]Escape sequences in communications are commonly used when a computer and a peripheral have only a single channel through which to send information back and forth (so escape sequences are an example ofin-band signaling).[19][20] They were common when mostdumb terminals usedASCII with 7 data bits for communication, and sometimes would be used to switch to a different character set for "foreign" or graphics characters that would otherwise been restricted by the 128 codes available in 7 data bits. Even relatively "dumb" terminals responded to some escape sequences, including the original mechanical Teletype printers (on which "glass Teletypes" or VDUs were based) responded to characters 27 and 31 to alternate between letters and figures modes.
Manycomputer keyboards have anEsc key (whereEsc is short forescape) even though it is generally not used for entering an escape sequence. Thevi text editor uses the key to exit from input mode.[21] Some application use the key to cancel an operation or navigate up a level of a nested context.[22]
The Baudot code, invented in 1870 and patented in 1874 by J. Baudot is […]
elements C0 and C1 of control characters […] a 5-bit code patented by Jean-Maurice-Emile Baudot (1845-1903) in 1874
Within the field, two consecutive apostrophes […]
Character combinations consisting of a backslash\ followed by a letter or by a combination of digits are calledescape sequences.5.1.1.2 Translation phases, 2.: Each instance of a backslash character (\) immediately followed by a new-line character is deleted, splicing physical source lines to form logical source lines. [...]+++ - "Escape Sequence" - This command initiates an escape sequence to return the modem to the on-line command mode
When a modem is in command mode, the modem can accept commands from you
vi commands […] Pressing the Esc (Escape) key is how you […]