Ubuntu – What does this bash escape sequence mean

bashcommand line

I've searched for a way to change terminal title and found this bash command:

echo -ne "\033]0;NEW_TITLE\007"

It works as it have to, but i'm now interested in what this "magic symbols" mean and how it works.

Best Answer

That uses an XTerm control sequence. echo with -e interprets certain sequences in the string given, in this case \033 became Esc, and \007 is the ASCII bell character (see man 7 ascii).

An Esc (represented as ^]) followed by ] is, in XTerm parlance, an Operating System Control code. Terminals which support it interpret it as given in the above link:

OSC Ps ; Pt ST
OSC Ps ; Pt BEL
          Set Text Parameters.  For colors and font, if Pt is a "?", the
          control sequence elicits a response which consists of the con-
          trol sequence which would set the corresponding value.  The
          dtterm control sequences allow you to determine the icon name
          and window title.
            Ps = 0  -> Change Icon Name and Window Title to Pt.
            Ps = 1  -> Change Icon Name to Pt.
            Ps = 2  -> Change Window Title to Pt.

OSC being ^]], the Ps in this case is 0, which sets Pt, in this case NEW_TITLE, as the terminal title.

Related:

Related Question