Actually, the escape sequence starts with the first escape character and ends with the
ESC and ASCII
0 is a parameter, corresponding to Ps in the description for xterm, while the text after the semicolon is Pt:
Ps = 0 -> Change Icon Name and Window Title to Pt.
Ps = 1 -> Change Icon Name to Pt.
Ps = 2 -> Change Window Title to Pt.
\033\007 are parts of the escape sequence which can be changed to other characters. The terminal treats the pair of bytes as a single control character (just as the 4 bytes
\007 are treated by
printf as a single character). Referring to XTerm Control Sequences, the section C1 (8-Bit) Control Characters may be helpful:
String Terminator (ST is 0x9c).
Operating System Command (OSC is 0x9d).
in understanding the beginning of Operating System Controls:
OSC Ps ; Pt ST
OSC Ps ; Pt BEL
\007) to end an escape sequence is an anomaly. It does not follow the standard (ECMA-48). Operating system controls should begin with either
ESC ] or 0x9d, and end with
ESC \ or 0x9c.
Long ago, the developer(s) of xterm added an escape sequence for setting the title. In X11R1 (1987), the program simply read the sequence until it got a nonprinting character. Later, in X11R4 (1989), someone improved this by terminating on a
BEL character. The standard had been around longer than that, but the reason for choosing
BEL rather than
ST is not known. Ultimately that was addressed in the late 1990s, by recognizing either (but keeping
BEL as an alternative since many users relied on hardcoded behavior with