Meaning of \[\e]0; in PS1 in .bashrc

The \e]0; is an escape sequence; \e is replaced with ASCII 27 (ESC), so the terminal receives the 4 characters ESC ] 0 ; tells xterm to set icon and title bar, that ends in BEL (\a).

So the sequence \e]0;STUFFGOESHERE\a will set the title of the terminal to STUFFGOESHERE. In your example it'll set the title to user/host/path.

FWIW, xterm escape sequences are documented at: https://www.x.org/docs/xterm/ctlseqs.pdf


The characters \e]0; in the line

PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"

are interpreted by the shell (equating \e to \033 the ASCII ESC escape character), beginning an escape sequence. The sequence ends on \a (likewise interpreted by the shell \007` ASCII BEL bell).

The 0 is a parameter (for what's known as an operating system command), which tells the terminal to change both icon and window titles.

Technically it ought to be \e\\ (ECMA-48), however that's not how it started. When the feature was first introduced in 1986, xterm terminated the title on the first non-printing character. The \a has been recognized as a string terminator by xterm since X11R4 in 1989 (when separate parameters 1 and 2 were added to distinguish the icon and window titles).

rxvt picked this up a couple of years later, and a few years later xterm was modified to also accept a standard string terminator. No particular point was made in the changelog, but it appeared in ctlseqs.ms first in August 1996. Generally when other terminals have implemented the feature they accept \a only.

Without the ending, the isolated escape character could be treated as an error in a terminal-specific manner (including ignoring the text altogether).

Further reading:

  • XTerm Control Sequences
  • ctlseqs.ms (August 1996).
  • ECMA-48: Control Functions for Coded Character Sets

Edit: fixed typo